Javascript 脚本仅在alert()未被切换时工作?
我有一个脚本,它在IE和chrome中工作,但在FF中不工作。。或者,如果我取消显示警告“x”的行,它在所有三种情况下都有效 在FF 3.6中,当脚本完成一半时,div首先可见。。它只是跳到“移动线”的中间Javascript 脚本仅在alert()未被切换时工作?,javascript,Javascript,我有一个脚本,它在IE和chrome中工作,但在FF中不工作。。或者,如果我取消显示警告“x”的行,它在所有三种情况下都有效 在FF 3.6中,当脚本完成一半时,div首先可见。。它只是跳到“移动线”的中间 函数Tween(){ 这个时间=0; 这个时间=800; 此.x_开始=0; 此点x_end=0; this.target_func=null; this.method_func=null; this.loop=null; 这个时间间隔=20; this.start=函数(){ if(!t
函数Tween(){
这个时间=0;
这个时间=800;
此.x_开始=0;
此点x_end=0;
this.target_func=null;
this.method_func=null;
this.loop=null;
这个时间间隔=20;
this.start=函数(){
if(!this.method_func){
this.method_func=this.regularEaseOut;
}
var_this=这个;
this.loop=setInterval(函数(){
如果(_this.set_time()>0){
var x=_this.method_func();
//警报(x);
_这个.target_func(x);
}
},这个时间间隔);
};
this.set_time=函数(){
this.time+=this.interval;
if(this.time>this.duration){
clearInterval(this.loop);
这个时间=0;
}
这次回来;
};
this.regularEaseInOut=函数(){
var t=这个时间;
var s=此.x_开始;
var e=此x_端;
var d=此时间;
如果((t/=d/2)<1){
返回c/2*t*t+b;
}
否则{
返回-c/2*((-t)*(t-2)-1)+b;
}
};
this.regularEaseIn=函数(){
var t=这个时间;
var s=此.x_开始;
var e=此x_端;
var d=此时间;
返回c*(t/=d)*t+b;
};
this.regularEaseOut=函数(){
var t=这个时间;
var s=此.x_开始;
var e=此x_端;
var d=此时间;
返回-e*(t/=d)*(t-2)+s;
};
}
var Tween=新Tween();
Tween.x_开始=200;
吐温x_端=1200;
Tween.target_func=函数(x){
document.getElementById('tst').style.left=x+'px';
};
Tween.start();
在按下Ok
之前,警报将停止代码的执行。检查这是否是问题的根源。这意味着什么不起作用
如果您的意思是它没有向右移动,那么它在我的FF 4.0.1中对我有效这有效:
<html>
<head>
<script type="text/javascript">
function Tween(){
this.time = 0;
this.duration = 800;
this.x_start = 0;
this.x_end = 0;
this.target_func = null;
this.method_func = null;
this.loop = null;
this.interval = 20;
this.start = function(){
if(!this.method_func){
this.method_func = this.regularEaseOut;
}
var _this = this;
this.loop = setInterval(function(){
if(_this.set_time() > 0){
var x = _this.method_func();
//alert(x);
_this.target_func(x);
}
}, this.interval);
};
this.set_time = function(){
this.time += this.interval;
if(this.time > this.duration){
clearInterval(this.loop);
this.time = 0;
}
return this.time;
};
this.regularEaseInOut = function(){
var t = this.time;
var s = this.x_start;
var e = this.x_end;
var d = this.duration;
if((t/=d/2) < 1){
return c/2*t*t + b;
}
else{
return -c/2 * ((--t)*(t-2) - 1) + b;
}
};
this.regularEaseIn = function(){
var t = this.time;
var s = this.x_start;
var e = this.x_end;
var d = this.duration;
return c*(t/=d)*t + b;
};
this.regularEaseOut = function(){
var t = this.time;
var s = this.x_start;
var e = this.x_end;
var d = this.duration;
return -e *(t/=d)*(t-2) + s;
};
}
function doYourThing() {
var tween = new Tween();
tween.x_start = 200;
tween.x_end = 1200;
tween.target_func = function(x){
document.getElementById('tst').style.left = x+'px';
};
tween.start();
}
</script>
</head>
<body onload="doYourThing()">
<div id="tst" style="position:absolute; top:200px; left:200px; height:100px; width:100px; background:#ff0000"></div>
</body>
</html>
函数Tween(){
这个时间=0;
这个时间=800;
此.x_开始=0;
此点x_end=0;
this.target_func=null;
this.method_func=null;
this.loop=null;
这个时间间隔=20;
this.start=函数(){
if(!this.method_func){
this.method_func=this.regularEaseOut;
}
var_this=这个;
this.loop=setInterval(函数(){
如果(_this.set_time()>0){
var x=_this.method_func();
//警报(x);
_这个.target_func(x);
}
},这个时间间隔);
};
this.set_time=函数(){
this.time+=this.interval;
if(this.time>this.duration){
clearInterval(this.loop);
这个时间=0;
}
这次回来;
};
this.regularEaseInOut=函数(){
var t=这个时间;
var s=此.x_开始;
var e=此x_端;
var d=此时间;
如果((t/=d/2)<1){
返回c/2*t*t+b;
}
否则{
返回-c/2*((-t)*(t-2)-1)+b;
}
};
this.regularEaseIn=函数(){
var t=这个时间;
var s=此.x_开始;
var e=此x_端;
var d=此时间;
返回c*(t/=d)*t+b;
};
this.regularEaseOut=函数(){
var t=这个时间;
var s=此.x_开始;
var e=此x_端;
var d=此时间;
返回-e*(t/=d)*(t-2)+s;
};
}
函数doYourThing(){
var tween=新tween();
tween.x_开始=200;
吐温x_端=1200;
tween.target_func=函数(x){
document.getElementById('tst').style.left=x+'px';
};
tween.start();
}
因此,使用onload确保只在加载文档后运行该方法。此外,还创建了一个实例变量(Tween),其名称与要实例化的“类”相同。这肯定会给你带来痛苦和痛苦。当它“不起作用”时会发生什么?有错误吗?还是奇怪的行为?或者什么都没有?只有脚本完成一半时,div才可见。。它只是跳转到错误控制台中的“移动行”检查的中间,对于任何JavaScript错误“un逃脱”,您是指“un注释”吗?您在表达式的中间使用<代码>(t/= d)< /代码>的原因是什么?这可能是个坏习惯。
<html>
<head>
<script type="text/javascript">
function Tween(){
this.time = 0;
this.duration = 800;
this.x_start = 0;
this.x_end = 0;
this.target_func = null;
this.method_func = null;
this.loop = null;
this.interval = 20;
this.start = function(){
if(!this.method_func){
this.method_func = this.regularEaseOut;
}
var _this = this;
this.loop = setInterval(function(){
if(_this.set_time() > 0){
var x = _this.method_func();
//alert(x);
_this.target_func(x);
}
}, this.interval);
};
this.set_time = function(){
this.time += this.interval;
if(this.time > this.duration){
clearInterval(this.loop);
this.time = 0;
}
return this.time;
};
this.regularEaseInOut = function(){
var t = this.time;
var s = this.x_start;
var e = this.x_end;
var d = this.duration;
if((t/=d/2) < 1){
return c/2*t*t + b;
}
else{
return -c/2 * ((--t)*(t-2) - 1) + b;
}
};
this.regularEaseIn = function(){
var t = this.time;
var s = this.x_start;
var e = this.x_end;
var d = this.duration;
return c*(t/=d)*t + b;
};
this.regularEaseOut = function(){
var t = this.time;
var s = this.x_start;
var e = this.x_end;
var d = this.duration;
return -e *(t/=d)*(t-2) + s;
};
}
function doYourThing() {
var tween = new Tween();
tween.x_start = 200;
tween.x_end = 1200;
tween.target_func = function(x){
document.getElementById('tst').style.left = x+'px';
};
tween.start();
}
</script>
</head>
<body onload="doYourThing()">
<div id="tst" style="position:absolute; top:200px; left:200px; height:100px; width:100px; background:#ff0000"></div>
</body>
</html>