Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lightbox click outside image to close

Tags:

jquery

I asked the author this but he said for me to add the contributions I want via Github, and I don't know how to do that as I'm not that knowledgeable with JavaScript. Hope you all can help. :)

Here's the link to the plugin: http://brutaldesign.github.io/swipebox/

Basically, how could I make the lightbox close by clicking anywhere outside the image? Like how most lightboxes function?

This lightbox does it perfectly how I want it: http://fancyapps.com/fancybox/ I dont use that lightbox because it doesn't have the swipe functionality that I need.

I do know it has to be something to do with the following function

.click

Thanks in advance!

like image 274
Airman Avatar asked Feb 16 '23 18:02

Airman


1 Answers

(updated with more events and better event delegation)

Try adding the following script to your page

<script>
    $(function(){
      $(document.body)
          .on('click touchend','#swipebox-slider .current img', function(e){
              return false;
          })
          .on('click touchend','#swipebox-slider .current', function(e){
              $('#swipebox-close').trigger('click');
          });
    });
</script>
like image 149
Gabriele Petrioli Avatar answered May 20 '23 22:05

Gabriele Petrioli