jquery - Show previous photo on click in the left half of the current photo in Colorbox -


in colorbox 1.6.0, default, click on displayed photo means next available photo displayed.

can customize colorbox display previous photo when user clicks left half of current photo?

i know how determine if mouse click happened in left or right half of div in general, considered implementing own click handler. click handler call prev() or next() public methods. though, don't know put click handler, colorbox default behaviour takes precedence.

the photos in html:

<a class="my-colorbox" href="..." rel="gallery-colorbox" title="first"></a> <a class="my-colorbox" href="..." rel="gallery-colorbox" title="second"></a> <a class="my-colorbox" href="..." rel="gallery-colorbox" title="third"></a> 

colorbox initialization:

$(".my-colorbox").colorbox({     rel: "gallery-colorbox",     photo: true,     loop: false,     transition: "none",     maxwidth: "90%",     maxheight: "90%",     ...internationalization... }); 

click handler - idea taken question - determining if mouse click happened in left or right half of div :

$("#cboxloadedcontent").click(function (e) {     var pwidth = $(this).innerwidth();     var poffset = $(this).offset();     var x = e.pagex - poffset.left;     if (pwidth / 2 > x)         $.colorbox.prev();     else         $.colorbox.next(); }); 

the problem #cboxloadedcontent not right place bind handler handler never called.

i believe code takes precedence (colorbox - function load).

... photo = settings.get('createimg'); ... if ($related[1] && (settings.get('loop') || $related[index + 1])) {     photo.style.cursor = 'pointer';     photo.onclick = function () {         publicmethod.next();     }; } 

looking @ demo colorbox, see when image displayed, topmost dom element (so 1 hit in click event) is:

<img class="cboxphoto" src="somepicture.jpg"> 

so attach event handler particular type of <img>.

$(".my-colorbox").colorbox({     /* options */     oncomplete: function() {         $(".cboxphoto").removeattr("onclick"); //stop default     } }); $(document).on("click", ".cboxphoto", function(e) {     /* left/right handler code here */ }) 

by adding .cboxphoto parameter filtering click event happens on document , saying i'm interested when happens element matches selector.

this harder needs i've logged issue.

update:

the issue has been responded , if use v1.6.1 oncomplete callback be:

function() {     $(".cboxphoto").off("click.cbox"); } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -