how to kill/reset a running jquery plugin?
I have a slideshow plugin which works fine. Alone...
I have 3 different buttons on one page. They all call the same jQuery slideshow plugin and load the slideshow with different i开发者_运维知识库mages into the same divider (with id="slideshow")
I remove the slideshow and it's elements from the #slideshow every single time before I load the new slideshow with the new images.
It would all work fine except that the more times I click on the buttons the messier the whole thing gets because the plugin is opened every single time and the plugin gets confused which images to show.
My question is. How can I completely kill a running plugin so the new one can load from the beginning. I tried empty(), die(), remove(), detach() APIs without successs.
Is there any other way?
Thanks.
http://muttley.freewebspace.com/slideshow/
Unfortunately there isn't a common way to destroy plugins on an element, if the plugin itself doesn't support it. You will probably have to remove the element you actually called the plugin on and create it again:
var oldDiv = $('#slideshow');
var parent = oldDiv.parent();
oldDiv.remove();
parent.append($('<div>').attr('id', 'slideshow'));
// Initialize slideshow here again
// Untested but shorter way:
$('#slideshow').replaceWith($('<div>').attr('id', 'slideshow'));
It all depends on the plugin. Does this plugin support multiple slideshows on a page? If so, instead of removing the contents of #slideshow
, perhaps it will work bette rif you replace #slideshow
itself with a new element.
精彩评论