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>
The loop should be greater than 10. You wrote it wrong. Also give an initial value of zero when declaring the loop.
Clear the timer and then execute a method to close the window