我已经写了一个函数window.setinterval,后面跟两个条件。完全按照我想要的方式在Firefox,Opera,IE中工作。在webkit引擎中,这个功能并没有被推广。window.setinterval函数在不同的浏览器引擎中表现不同
x = window.setInterval(function() {
if(a.speed >= a.maxSpeed && b.speed >= b.maxSpeed && c.speed >= c.maxSpeed) {
a.stop();
b.stop();
c.stop();
}
if(a.speed === 0 && b.speed === 0 && c.speed === 0 && completed === 3) {
window.clearInterval(x);
enableControl();
printResult();
enableControl();
}
}, 100);
我设置的时间间隔,其中均达到max.speeds时,停止功能应该被调用,如果速度为0,应显示的结果。在Mozilla,IE,Opera的工作完全按照我的意图。但是在webkit中,第一个条件本身没有被执行。无限循环正在运行。
我试过嵌套,如果也,即使然后第一条件如果条件不被执行。请帮我解决这个问题。
如果这不是一个正确的评价,我可以在c.stop()之后触发超时并手动将a,b,c的速度设置为0,然后启用控制和显示结果?
这是您要求的停止功能。
Slot.prototype.stop = function() {
var _this = this,
limit = 30;
clearInterval(_this.si);
_this.si = window.setInterval(function() {
if(_this.speed > limit) {
_this.speed -= _this.step;
$(_this.el).spSpeed(_this.speed);
}
if(_this.speed <= limit) {
_this.finalPos(_this.el);
$(_this.el).spSpeed(0);
$(_this.el).spStop();
clearInterval(_this.si);
$(_this.el).removeClass('motion');
_this.speed = 0;
}
}, 100);
};
速度是否浮点?如果是,速度如何变为0? –
有什么错误?你不显示a,b,c是什么,所以我们不能真正帮忙。 – kennypu
@ t.niese不,它不是浮点数。 – Abhishek