I made a window shaking effect, but the newly opened window has a shaking effect, but how to clear the effect, and how to close it after clearing the effect, I don’t know how to write...
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>窗口抖动</title>
</head>
<body>
<script>
var w=window.open('','', 'width=100,height=100');
w.resizeTo(300,300);
var loop;
var timer;
var offX;
var offY;
var status = 1;
timer = setInterval(function(){
w.moveTo(100,100);
if(loop<10){
clearInterval(timer);
}
status = Math.random()*10 > 5 ? 1 : -1;
offX = Math.random()*20*status;
offY = Math.random()*20*status*-1;
w.moveBy(offX,offY);
loop++;
},10);
</script>
</body>
</html>
phpcn_u15822017-05-18 10:59:11
var w=window.open('','', 'width=100,height=100');
w.resizeTo(300,300);
var loop = 0; // 设置默认值
var timer;
var offX;
var offY;
var status = 1;
timer = setInterval(function(){
w.moveTo(100,100);
// 设为大于
if(loop > 10){
clearInterval(timer);
}
status = Math.random()*10 > 5 ? 1 : -1;
offX = Math.random()*20*status;
offY = Math.random()*20*status*-1;
w.moveBy(offX,offY);
loop++;
},10);
w.close() // 关闭窗口
高洛峰2017-05-18 10:59:11
setTimeout(function () {
clearInterval(timer);
},1000);
setTimeout(function () {
w.close();
},2000)
黄舟2017-05-18 10:59:11
if(loop>10){
clearInterval(timer);
}
The loop should be greater than 10. You wrote it wrong. Also give an initial value of zero when declaring the loop.