Search code examples
jqueryprettyphoto

Closing prettyPhoto onclick


I cant figure out how to simply close a prettyPhoto.

I use following code to open a dynamic instance.

$(document).ready(function () {
    $.fn.prettyPhoto();
    $.prettyPhoto.open('<?php echo $path; ?>/news/<?php echo $get_hot_news[img]; ?>');
});

There is by default a close button in bottom right corner and the prettyPhoto frame closes if you click outside of it but not all people figure that out, thats why I need to close it upon cliking anywhere inside the prettyPhoto itself.


Solution

  • How about closing when the user clicks anywhere in the body of the page?

    $('body').on('click',function() {
        $.prettyPhoto.close();
    });