我有一个插件按照这里建议的锅炉板结构:
http://markdalgleish.com/2011/05/creating-highly-configurable-jquery-plugins/
这个插件正在响应我想要的Chrome,但是我得到了Internet和FireFox错误
您可以在这里查看正在使用的插件,http://websonalized.com/myplugin.php
MSIE开发人员控制台中的错误(调试):
无效参数myplugin.js,第84行字符5
FIREFOX中的错误:
错误:无用的setTimeout调用(缺少参数周围的引号?)
setTimeout(animateSlide(sliderImage),3000);
这是相关的代码位
...
this.$slides.each(function(i){
slide_config = $.extend({
duration: 3000,
squares: 225, //it will display the closest 'perfect square' number of tiles
transition: 'linear'
}, $(this).data());
var sliderImage = $(this).find('.slidebg');
...
setTimeout(animateSlide(sliderImage), 3000);
function animateSlide(s){
console.log('ANIMATED IMAGE SLIDER ' + i);
console.log(s);
$(s).show('explode', { pieces: slide_config.squares }, 5000);
};
...如果我将setTimeout位重写到,那么错误就消失了
...
this.$slides.each(function(i){
slide_config = $.extend({
duration: 3000,
squares: 225, //it will display the closest 'perfect square' number of tiles
transition: 'linear'
}, $(this).data());
var sliderImage = $(this).find('.slidebg');
...
setTimeout(function(){$(sliderImage).show('explode', { pieces: slide_config.squares }, 5000);}, 3000);
...但是slide_config.squares的值并不对应于这个实例,而是由最后一个幻灯片数据设置的值。
this.$slides.each(function(i){
slide_config = $.extend({
duration: 3000,
squares: 225, //it will display the closest 'perfect square' number of tiles
transition: 'linear'
}, $(this).data());我想这与背景有关。有人能帮我修复和理解我应该如何使用setTimeoff吗?
修复意味着我能够在浏览器FF、IE和Chrome中setTimeout w/o错误,而每个实例的slide_config.squares值等于每个幻灯片对象设置的值或默认值(即slide_default )。
注意:对于第一个代码示例,slide_config.squares的值与我所期望的一样,即根据幻灯片对象或slide_config默认值设置。同样,在Google中,该代码在第一段代码中似乎运行良好。
发布于 2012-09-24 03:09:28
需要将slide_config声明为each()回调中的局部变量,方法是编写
var slide_config = ...;这将使每个setTimeout关闭它自己的变量副本,而不是让它们共享一个全局变量。
https://stackoverflow.com/questions/12558382
复制相似问题