stef
stef

Reputation: 27799

jQuery cycle: custom callback?

This snippet runs my slideshow, which consists of a series of images. At the top of the slideshow I have "image x of y". Is it possible to add a callback that is tied to each the prev and next buttons? One callback would add 1 to the x and the other subtract.

So this is some form of pagination for which I could not find an out of the box solution with the cycle plugin.

I could obviously attach my own functions to #prev and #next but the count would still get incremented even if no other images are shown. I need to be able to detect whether or not images are being "slided" in to view.

$('#prod_list').cycle({ 
    fx:     'scrollHorz', 
    prev:   '#prev', 
    next:   '#next', 
    timeout: 0 ,
    nowrap: 1,          
});

Upvotes: 0

Views: 1555

Answers (2)

Fletch
Fletch

Reputation: 5259

Checkout the description of "onBefore" and "onAfter" under Callbacks at http://jquery.malsup.com/cycle/int2.html. Viewing source of the page, you see the full example of how to do it.

Upvotes: 0

Fermin
Fermin

Reputation: 36111

Can't you use the prevNextClick option, as defined in the Cycle Options?

This takes a function in the following format:

function(isNext, zeroBasedSlideIndex, slideElement)

There are also several other options that can help with pagination.

  • pagerAnchorBuilder
  • allowPagerClickBubble
  • pagerEvent
  • pagerClick
  • pager

Upvotes: 1

Related Questions