<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>每天一个JavaScript实例-使用带有定时器的函数闭包</title>
<style>
#redbox{
position:absolute;
left:100px;
top:100px;
width:200px;
height:200px;
background-color:red;
}
</style>
</head>
<body>
<div id ="redbox"></div>
<script>
window.onload = function(){
document.getElementById("redbox").onclick = move;
}
function move(){
var x = 100;
intervalId = setInterval(function(){x+=5;var left = x +"px";document.getElementById("redbox").style.left = left;},100)
}
</script>
</body>
</html>
每天一个JavaScript实例-使用带有定时器的函数闭包
最新推荐文章于 2023-04-29 12:04:47 发布