Search code examples
jqueryjcarousel

jCarousel Auto Scroll On Button Click


How do I modify this jCarousel example so that when the left or right button is clicked, the carousel will continually scroll in that direction: http://sorgalla.com/projects/jcarousel/examples/static_auto.html.

At the moment, the example cancels the automatic scrolling once any of the buttons are clicked which is something I want to avoid.

I am quite new to jCarousel and any help would be appreciated.


Solution

  • It doesn't look like jCarousel has built in support for automatic scrolling in reverse.

    In order to do this, I had to modify the startAuto function to accept negative numbers. Then, when it got a negative number, it scrolls the other way automatically.

    I also updated the click events on the next/previous buttons to call startAuto with the negative value if it is currently scrolling in the other direction.

    Code here:

    http://jsfiddle.net/28uph9g5/