2016-5-17 17:13:35-
在浏览器流畅运行的代码,在微信打开竟然卡到爆炸,十分不流畅
即使已经封装好了
(function() {
var lastTime = 0;
var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || // Webkit中此取消方法的名字变了
window[vendors[x] + 'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame) {
window.requestAnimationFrame = function(callback, element) {
var currTime = new Date().getTime();
var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
var id = window.setTimeout(function() {
callback(currTime + timeToCall);
}, timeToCall);
lastTime = currTime + timeToCall;
return id;
};
}
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}
}());
出现该问题的代码,持续找原因ing
/*
*/
$("#start").click(function() {
var start = 0, during = 100;
var _run = function() {
start++;
var the_top = Tween.Quad.easeOut(start, ball.x , -600, during);
$("#ball1").css({"top":the_top});
if(start < during)requestAnimationFrame(_run);
};
_run();
})