31.htm

来自「介绍了javascript的常用的函数」· HTM 代码 · 共 45 行

HTM
45
字号
<html>
<head>
<title>反弹文字</title>
<script language="javascript">
<!--
	x = 0;
	y = 0;
	controlx = true;
	controly = true;
	function moveText(){ 
		docWidth  = parseInt(document.body.clientWidth);
		docHeight = parseInt(document.body.clientHeight)-20;
		textWidth    = parseInt(txt.style.width);
		txt.style.left = x;
		txt.style.top  = y;
		if(controlx && docWidth-textWidth > x){
			x+=2;
		}else{
			controlx = false;
		}
		if(!controlx && x > 0){
			x-=2;
		}else{
			controlx = true;
		}
		
		if(controly && docHeight > y){
			y+=2;
		}else{
			controly = false;
		}
		if(!controly && y > 0){
			y-=2;
		}else{
			controly = true;
		}
		setTimeout("moveText()",1);
	}
//-->
</script>
</head>
<body onLoad="moveText()">
<div id="txt" style="position:absolute;width=65">反弹文字</div>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?