jQuery 如何销毁/移除/解除绑定 Flexslider
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13213913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to destroy/remove/unbind a Flexslider
提问by HandiworkNYC.com
There are a few discussions on the github page regarding the destroy method, and a couple questions on stack, but there hasn't been a straightforward answer or solution yet, that I was able to find after alot of searching.
在 github 页面上有一些关于 destroy 方法的讨论,还有一些关于堆栈的问题,但还没有一个直接的答案或解决方案,我经过大量搜索后找到了。
The current version of flexslider http://www.woothemes.com/flexslider/does not have a destroy method. In the notes it says that the former version 1.8 does, but using that method does not work.
当前版本的 flexslider http://www.woothemes.com/flexslider/没有 destroy 方法。在注释中它说以前的版本 1.8 可以,但使用该方法不起作用。
I need to unbind a flexslider element then call .flexslider() on another element as I don't want several sliders running simultaneously.
我需要解除 flexslider 元素的绑定,然后在另一个元素上调用 .flexslider() ,因为我不希望多个滑块同时运行。
How can I do this? Note: removing nav elements, removing classes, unwrapping the UL and removing ".clone" li
's is not good enough! I want to completely return the slider element to its original state!
我怎样才能做到这一点?注意:删除导航元素、删除类、解开 UL 并删除 ".clone"li
还不够好!我想将滑块元素完全恢复到原始状态!
Right now I clone the slider before initializing flexslider, then use .after()
to insert the clone after the slider, then remove the slider. But this seems like a very heavy handed approach to me.
现在我在初始化 flexslider 之前克隆滑块,然后使用.after()
在滑块后面插入克隆,然后删除滑块。但这对我来说似乎是一种非常严厉的方法。
$projCur.addClass('flexslider').flexslider({
animation: "slide",
animationSpeed: 500,
slideshow: false,
manualControls: '.dot-nav li a'
});
Thanks!
谢谢!
回答by Teegan
A Github user has submitted a pull request to add a destroy method for the plugin. https://github.com/woothemes/FlexSlider/pull/771
一个 Github 用户提交了一个 pull request 来为插件添加一个 destroy 方法。 https://github.com/woothemes/FlexSlider/pull/771
I took this users version of the plugin with his destroy method and it works great for me. I got it from https://github.com/bradgreens/FlexSlider/tree/release-2-2-0
我使用他的 destroy 方法获取了这个用户版本的插件,它对我来说非常有用。我从https://github.com/bradgreens/FlexSlider/tree/release-2-2-0得到它
回答by Natacha Beaugeais
The destroy method never works for me.
destroy 方法对我不起作用。
The only reliable solution I've found (since the current version 2.2.2) is to completely remove the flexslider element from the DOM, then reinstate it.
我发现的唯一可靠的解决方案(从当前版本 2.2.2 开始)是从 DOM 中完全删除 flexslider 元素,然后恢复它。
Something like:
就像是:
$('.flexslider').remove();
// re-insert clean mark-up so flexslider can reset itself properly
$('.flexslider-container').append('<div class="flexslider"><ul class="slides"></ul></div>');
Then I reinitialise the flexslider from scratch:
然后我从头开始重新初始化 flexslider:
var imglist = '<li><img ...></li><li><img ...></li>...';
$('.flexslider ul.slides').html(imglist);
$('.flexslider').flexslider({
...
});
I also find this method is more reliable than adding and removing slides in order to get the slider to update itself.
我还发现这种方法比添加和删除幻灯片以使滑块自行更新更可靠。
回答by Daniel Waters
Have you tried detach and attach? this will keep the state and even events of anything detached.
您是否尝试过分离和附加?这将使任何事物的状态甚至事件保持分离。
var flex = $('.flexslider').detach(); //detach
$('body').append(flex); //reattach
回答by J.BizMai
For me, I found this solution :
对我来说,我找到了这个解决方案:
$('.logo-carousel').flexslider({
move : 0
});