注册 登录
编程论坛 JavaScript论坛

jquery中如何关闭settimeout循环

pigzee 发布于 2010-10-14 21:28, 1070 次点击
如题
js中
$timer=setTimeout("Times()",1000); //在1秒后运行Times();
function Times(){alert('Hello world')}; //Times() 的内容;
 clearTimeout($timer); //移除设置

jquery中使用了$,如何结束循环呢?我的函数是含有参数的。呵呵。

我一个22分,哈哈,给的分不多,见谅!
1 回复
#2
pigzee2010-10-14 21:35
嘿嘿,我想到一个方法,设置一个状态位,呵呵。
类似,呵呵
function Shift(Obj){
                    var me = this;
                    if (typeof (Obj)=="string") this.Obj = document.getElementById(Obj);
                    else this.Obj = Obj;
                    this.Timer = 10;
                    this.Move = function (y1,y2)
                    {
                        
                        if(y1 == y2){
                            alert('---');
                            $("#cloneList").empty();
                        }else{
                            var y1 = parseInt(this.Obj.style.top,10);
                            var yc = Math.ceil(Math.abs(y1-y2)/20);
                            this.Obj.style.top = y1 + yc * (y1<y2?1:-1) + "px";
                            setTimeout(function (){me.Move(y1,y2)},me.Timer);
                        }                  
                    }
                }
1