js定时器-----离开当前页面原本匀速运动的div加速了,回到页面若干时间恢复匀速???
求答
下面是我的js代码
window.onload = function () {
let cube = document.querySelector('.cube')
let timer = null
let x = 0; y = 0;
function rotate() {
cube.style.transform = 'rotateX(' + x + 'deg)' + '' + 'rotateY(' + y + 'deg)';
x += 30
y += 45
}
function stop() {
clearInterval(timer)
}
clearInterval(timer);
timer = setInterval(() => {
rotate();
}, 1000);
}来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4687/viewspace-3132977/ ,如需转载,请注明出处,否则将追究法律责任。