0

我在尝试清除对象中设置的超时时遇到了麻烦,我有一个这样的对象:

var banner=function(options){

    this.s_btn=options.s_btn;
    this.interval=null;

    this.pos=0;
    this.maxPos=4;

    var _obj=this;

    _obj.s_btn.bind("click",function(){
        //clear Timeout
        clearTimeout(_obj.interval);
        _obj.interval=null;
        //Change banner with some FX
        _obj.changeBanner($(this).index());
        //start timeout Again
        _obj.setInt();
    });
    //Function that starts timeout
    this.setInt=function(){
        _obj.interval=setTimeout(function(){
            //where slide to change
            var to=(_obj.pos==_obj.maxPos)?0:Number(_obj.pos)+1;
            //Change banner with some FX
            _obj.changeBanner(to);
            //starts bucle
            _obj.setInt();
        },_obj.time);
    }
    _obj.setInt();
}

有两种方法: - changeBanner:它改变横幅的图像 - setInt:它启动一个超时循环,每 X 毫秒执行一次 changeBanner 函数。

我也将点击事件绑定到一个元素;我想重置超时循环,但我做错了什么。:S

我将超时函数存储在 this.interval 中,并在单击之前调用的元素时将其清除。

4

2 回答 2

0

我通过将 setTimeout 和 clearTimeout 引用到窗口来解决它:

window.setTimeout(_obj.interval)

window.clearTimeout(_obj.interval)
于 2013-04-28T19:47:46.233 回答
0

您在示例中拼写错误的间隔

清除超时(_obj.inerval)

于 2013-04-28T19:46:38.703 回答