JS实现很烦人的广告

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>

<body>
	<div id="one" style="position:absolute;background:red;left:0;top:0;width:100px;height:100px;font-size:12px">这里是广告!</div>
    <script language="javascript">
		var x = 0;
		var y = 0;
		
		var xs = 10;
		var ys = 10;
		
		var one = document.getElementById("one");
		var dt = setInterval("move()",100);	// 每100毫秒移动一次
		
		// 移动方法
		function move() {
			x+=xs;
			y+=ys;
			
			if (x >= document.body.clientWidth-one.offsetWidth-5 || x <= 0) {
				xs = -1*xs;
			}
			
			if (y >= document.body.clientHeight-one.offsetHeight-5 || y <= 0) {
				ys = -1*ys;
			}
			
			one.style.left = x;
			one.style.top = y;
		}
		
		// 当鼠标放上之后停止漂移
		one.onmouseover = function(){
			clearInterval(dt);	
		}
		
		// 当鼠标离开之后继续漂移
		one.onmouseout = function(){
			dt = setInterval("move()",100);	
		}
	</script>
</body>
</html>

你可能感兴趣的:(JS实现很烦人的广告)