Search code examples
javascriptjqueryjquery-cycle2

How can I differentiate between a click on a pager item and a click on a prev/next item in Cycle2?


I'm using Mike Alsup's awesome Cycle2 jquery plugin on a slideshow that features both a custom pager element (thumbnails) and previous/next buttons. How can I trigger an action using the cycle-after event only if the pager was clicked.

$('#myslideshow').on('cycle-after',function(e, optionHash, outgoingSlideEl, incomingSlideEl, forwardFlag){
    // Do something here only if the pager was clicked.
});

I don't want to use the click event from the pager element - that won't wait until the slide transition is complete, it fires right away, and seems to conflict with the slideshow animations sometimes.


Solution

  • How about setting a boolean value to true during the click event of your pager item or the cycle-pager-activated event, and using that value inside the cycle-after event, then reset it back to false.