码迷,mamicode.com
首页 > 编程语言 > 详细

每天一个JavaScript实例-使用带有定时器的函数闭包

时间:2014-09-29 03:03:07      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   io   os   使用   ar   java   div   

<!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实例-使用带有定时器的函数闭包

标签:style   http   color   io   os   使用   ar   java   div   

原文地址:http://blog.csdn.net/waiting7436/article/details/39651675

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!