首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery插件setTimeout IE ( Internet 8)错误

jQuery插件setTimeout IE ( Internet 8)错误
EN

Stack Overflow用户
提问于 2012-09-24 03:07:15
回答 1查看 654关注 0票数 0

我有一个插件按照这里建议的锅炉板结构:

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);

这是相关的代码位

代码语言:javascript
复制
...

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位重写到,那么错误就消失了

代码语言:javascript
复制
...

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的值并不对应于这个实例,而是由最后一个幻灯片数据设置的值。

代码语言:javascript
复制
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中,该代码在第一段代码中似乎运行良好。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-24 03:09:28

需要将slide_config声明为each()回调中的局部变量,方法是编写

代码语言:javascript
复制
var slide_config = ...;

这将使每个setTimeout关闭它自己的变量副本,而不是让它们共享一个全局变量。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12558382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档