views:

387

answers:

2

I have a slideshow running with the awesome cycle plugin, and when you click a button in the show, I show a hidden layer on the page and send a 'pause' command to cycle. I'm having two problems:

  1. When the pause command is received, cycle immediately flips back to the 1st slide in the sequence (why??), and doesn't hit my before/after callbacks.

  2. After closing the layer, I send a 'resume' command to cycle. The slideshow resumes (from the 1st slide, where the pause left it), but now cycle doesn't call my before/after callbacks at all, even as the slideshow progresses.

So I guess my question is: how can I properly pause/resume the slideshow so these strange behaviors don't occur? (And just to be completely clear and avoid any confusion, this isn't about the "pause on hover" feature, which is actually working fine for me. :-)

Here's my cycle() init, and my callback functions. (Why am I manually tracking the nextSlide, you ask? Because the built-in value for the current slide doesn't get updated properly for the before/after callbacks.)

  $(document).ready(function() {
    $('#slideshow').cycle({
      fx: 'fade',        // choose your transition type, ex: fade, scrollUp, shuffle, etc...
        timeout:       4000,  // milliseconds between slide transitions (0 to disable auto advance)
        speed:         1000,  // speed of the transition (any valid fx speed value)
        pause:         1,     // true to enable "pause on hover"
        delay:         0,     // additional delay (in ms) for first transition (hint: can be negative)
        slideExpr:     'img',  // expression for selecting slides (if something other than all children is required)
        before:       moveArrow, // function to call when moving to next slide
        after:       upd, // function to call when moving to next slide
        fastOnEvent:   'fast',
    });
  });

  var nextSlide = 0;

  function upd(a, b, c) {
    nextSlide = nextSlide + 1;        // track which slide we're on
    c = $('#slideshow img').length;
    if(nextSlide > (c - 1)) nextSlide = 0;   // wrap back to 1st
  }

  // move indicator showing which slide we're on
  function moveArrow(a, b, c) {
    $('#slide-indicator').attr('class', 'c'+nextSlide);

    $(".clickmap").hide();          // hide other clickmaps
    $(".clickmap.c"+nextSlide).show();    // show map for this slide

    return true;
  }

Thanks for any thoughts on this--

best, Eric

A: 

You didn't show your code for sending the pause command. Something is definitely wrong there because pause does NOT reset the slideshow to the first slide.

Also, you don't need to keep track of the slide index yourself. The third arg to the before/after callbacks is an options object that has the internal state of the slideshow. On that object you will find 'currSlide' and 'slideCount' properties, among many others.

malsup
Thanks for the tip re: currSlide. I was using that before and was getting some strange results, but I just tried it again and it's fine now, so maybe I made a mistake previously.Additionally, I did a bunch more testing and see part of what's going on. When cycle('pause') is called, all elements in the #slideshow div are set to "top: 0; left: 0; position: absolute; display: none; opacity: 0" and the z-index of every element is reset as well. (cont'd)
Eric
This is causing some of the behavior I'm seeing: I have several layers on top of each other for the slideshow, so that explains the first slide reappearing.Part of what's going on is that, inside my #slideshow div, I have other divs (that are not part of the slideshow but need to be in there), so when I set up cycle() I tell it to only pick the IMG elements inside of the #slideshow div. But I think on the 'pause' it's ignoring that and just resetting everything in there.
Eric
There are a few different things going on here and this thread is getting a little crazy, but FWIW I found an issue with Mac Firefox, which is probably helping explain at least some of the weirdness. Try http://themepark.com/eric from Mac Firefox...
Eric
A: 

Thanks for sharing cycle plugin.

saudi