0

I'm running into a problem with jQuery, so I think I've figured out a workaround, but need help.

I currently attach a cycle() slideshow to my div like this:

function startSlideshow() {
    $('#slideshow').cycle({ some parameters });
}

When I pause and restart this slideshow, it exhibits weird behavior, due to bugs in the cycle plugin. So my workaround idea is this: to destroy the existing cycle() and then just recreate it on the fly.

I can easily recreate it by calling startSlideshow() again... but how do I kill the old cycle() that's attached to the div?

I guess I'm looking for a way to "unset" or "unbind" it completely (and jQuery's unbind() method isn't it).

Thanks-- Eric

Community
  • 1
  • 1
Eric
  • 5,104
  • 10
  • 41
  • 70

3 Answers3

2

Use the the plugins destroy command, it has been added to version 2.80

$('#slideshow').cycle('destroy');
Marko
  • 71,361
  • 28
  • 124
  • 158
  • Hmm. Strangely, 'destroy' seems to leave it in a weird state. Calling 'destroy' and then immediately starting it again definitely does not restart it normally. – Eric Aug 06 '10 at 23:19
  • I added this line after the destroy command: $("#slideshow, #slideshow *").attr("style", ""); It removes the inline styling created by cycle. – Martin Sep 20 '12 at 16:35
2

You can use $('#slideshow').cycle('destroy');

But are you sure the weird behaviour is due to the cycle plug-in having bugs ? and not improper usage of it ?

How do you pause and restart the cycling ?

Gabriele Petrioli
  • 191,379
  • 34
  • 261
  • 317
  • Hi Gaby-- as best I can tell, there are some issues with the z-index and how cycle() handles things. My page is really complicated and I can't easily reproduce it outside of the page, but I'm definitely calling it normally. Check out the link in the 1st line of my question (above, top of this page) to see the other question I posted, and you can see how I'm calling the code. Thanks for the reply. – Eric Aug 06 '10 at 23:19
1

First you remove the attached cycle command. Then you remove the inline styles created by cycle:

$("#slideshow").cycle("destroy");
$("#slideshow, #slideshow *").removeAttr("style");
startSlideshow(); // recreate cycle slideshow
Martin
  • 2,302
  • 2
  • 30
  • 42