Adding a Pause Button to jCarousel (slight fix)

I was recently asked by a client to add a pause button to the jCarousel-powered carousel on their site.

To do this, I used this post by Jeremy Mikola (thanks Jeremy). Here's his code:

    vertical: true, 
    scroll: 1, 
    auto: 5, 
    initCallback: function(jc, state) { 
      if (state == 'init') { 
        // Insert a play/pause button between the prev/next buttons 
        $('div.jcarousel-prev-vertical').after('<div class="jcarousel- 
toggle-vertical" style="display:block;"></div>');   

        /* Override the internal startAuto() method, which is called 
         * animations complete, to prevent next/prev buttons from 
         * the timer while in the pause state. 
        jc.startAutoOrig = jc.startAuto; 
        jc.startAuto = function() { 
          if (!jc.paused) { 

        jc.pause = function() { 
          jc.paused = true; 
        };  = function() { 
          jc.paused = false; 

        // Click event for playback toggle button, conditionally calls 
          if (this.timer === null) { 
          } else { 

However, I had a bit of trouble with it and had to make a change, as follows:

For some reason, "this.timer === null" wasn't working for me. 

I replaced that section with: 

        if (jc.paused) { 
        } else { 

Seemed logical and seems to work... 

Hope that helps someone. 

I did try to post this as a comment on Nabble, but it's still pending, so I'm posting here for now.

Digg This
Reddit This
Stumble Now!
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Buzz this!

Printed from: © divydovy 2019


RSS feed for comments on this post , TrackBack URI

Leave a Reply