jQuery 如何为动态加载重新初始化 flexslider

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16282819/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 16:51:40  来源:igfitidea点击:

How to reinitialize flexslider for a dynamic loading

javascriptjquerysliderflexslider

提问by MENTAL

I got a problem with flexslider, I need to download my picture in base64 from a webservice. After the download is complete, I make an .append()to add my slide...

我的 flexslider 有问题,我需要从网络服务以 base64 格式下载我的图片。下载完成后,我做一个.append()添加我的幻灯片...

But sometimes, everything is added perfectly but the slider doesn't reload correctly So I get code like this : screen1

但有时,一切都完美添加,但滑块无法正确重新加载所以我得到这样的代码: 屏幕1

instead of code like this : screen2

而不是这样的代码: 屏幕2

How can I reinitiate my slider in this case ?

在这种情况下如何重新启动我的滑块?

回答by MENTAL

Solution found ! Just add this line of code to remove the old slider ref if exists

解决方案找到了!只需添加这行代码即可删除旧的滑块引用(如果存在)

$('#flexslider').removeData("flexslider");

$('#flexslider').removeData("flexslider");

回答by Jonny Sooter

When the download is complete, and after you make the append, try using the method again.

下载完成后,在进行追加后,再次尝试使用该方法。

$('.flexslider').flexslider();

That should reinitiate it and account for new content.

这应该重新启动它并解释新内容。