清楚定时器清除不了

图片描述

   return (function(){
                    timers=null;
                   
                    if(opts.autopay){
                        slider.autopay(obj,opts);
                    }
                    slider.clearTimers(obj,opts,timers);
                })()
   
    autopay:function(obj,opts){
                   return (function () {
                       if(opts.times&&opts.autopay){
                               clearInterval(timers);
                               timers==null;
                              if(timers==null){
                                  timers=setInterval(function () {
                                      slider._right(obj,opts);
                                  },opts.times);
                              }else{
                                 console.log(timers);//这里返回有数值,上面明明清除了定时器
                              }
                       }
                   })();
                },
                clearTimers:function(obj,opts,timers){
                   return (function () {
                           obj.hover(function(){
    //                           opts.autopay=false;
                               clearInterval(timers);
                           },function(){
    //                           opts.autopay=true;
                               slider.autopay(obj,opts);
                           });
                   })();
                }
阅读 3k
2 个回答

修改答案: timer记录的是定时器的一个数值,清除时是按照数值清除的,并不会将timers变为null


timers==null;
if(timers==null){
    timers=setInterval(function () {
        slider._right(obj,opts);
    },opts.times);
}else{
    console.log(timers);//这里返回有数值,上面明明清除了定时器
}

你确定进入了console.log?应该是永远都进不了吧

clearInterval(timers)

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题