为什么插件没有动态初始化

时间:2012-05-08 08:11:41

标签: javascript jquery

$("#" + IdToInitialize).cycle("destroy").cycle({
    fx: $("#cyclescroll").val(),
    easing: $("#cyclebounce").val(),
    speed: 1000,
    timeout: 2000
});

问题是什么,为什么循环插件没有使用新设置再次初始化?

2 个答案:

答案 0 :(得分:0)

尝试这种方式: -

$("#" + IdToInitialize).cycle("destroy");
$("#" + IdToInitialize).cycle({
    fx: $("#cyclescroll").val(),
    easing: $("#cyclebounce").val(),
    speed: 1000,
    timeout: 2000 
}); 

确保

$("#cyclescroll").val()应将值返回为fade, scrollUp, shuffle $("#cyclebounce").val()应将值返回为easeInOutBack, easeOutBack

参考 Cycle Options

答案 1 :(得分:0)

用于重新初始化插件的其中一个值不正确。 Eitehr IdToInitialize,fx或easing不正确。

http://jsfiddle.net/ny2Tj/3/

点击按钮后,以下工作正常:

<div id="sliders">
<div id="slideshow">
<img src="http://scienceblogs.com/startswithabang/upload/2012/04/why_should_there_be_dark_matte/AS17-148-22727_lrg-thumb-500x500-74032.jpeg" />
<img src="http://weblogs.marylandweather.com/4526619322_1912218db8.jpg" />
<img src="http://www.silverstar-academy.com/Blog/wp-content/uploads/2012/03/03-14-12N00184967.jpg" />
<img src="http://cdn.the2012scenario.com/wp-content/uploads/2011/11/sunspot-500x500.jpg" />
</div>
<div id="pager"></div>
</div>

<button id="reinit">Reinit</button>

JS:

$('#slideshow').cycle({fx:'scrollHorz', pager: '#pager'});
$('#reinit').click(function() {
$('#slideshow').cycle('destroy').cycle({fx:'scrollVert'}); // change effect remove pager    
});