代码简介:
JavaScript水平循环飞舞的图片,这个功能我们在编写游戏的时候能用得上,当然这里的图片你也可以把它换作是文字,JS只管ID而不管内部会是什么内容,本代码修改起来也方便,希望有朋友喜欢。
代码内容:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>让图片水平循环飞舞的JavaScript代码 - www.webdm.cn</title>
</head>
<body onload="next();">
<script language="JavaScript">
var pos1=-95;
var pos2=-95;
var pos3=-95;
var speed1 = Math.floor(Math.random()*10)+2;
var speed2 = Math.floor(Math.random()*10)+2;
var speed3 = Math.floor(Math.random()*10)+2;
function next() {
pos1 += speed1;
pos2 += speed2;
pos3 += speed3;
if (pos1 > 795) pos1 = -95;
if (pos2 > 795) pos2 = -95;
if (pos3 > 795) pos3 = -95;
if (document.layers) {
document.layers[0].left = pos1;
document.layers[1].left = pos2;
document.layers[2].left = pos3;
}
else {
mouse1.style.left = pos1;
mouse2.style.left = pos2;
mouse3.style.left = pos3;
}
window.setTimeout("next();",10);
}
</script>
<div id="mouse1"
style="HEIGHT: 100px; LEFT: 0px; POSITION: absolute; TOP: 165px; WIDTH: 100px">
<dd><img alt border="0" src="http://www.webdm.cn/images/wall1_s.jpg" width="80" height="70" /> </dd>
</div><div id="mouse2"
style="HEIGHT: 100px; LEFT: 0px; POSITION: absolute; TOP: 250px; WIDTH: 100px">
<dd><img alt border="0" src="http://www.webdm.cn/images/wall2_s.jpg" width="70" height="60" /></dd>
</div><div id="mouse3"
style="HEIGHT: 100px; LEFT: 0px; POSITION: absolute; TOP: 333px; WIDTH: 100px">
<dd><img alt border="0" src="http://www.webdm.cn/images/wall3_s.jpg" width="72" height="61" /></dd>
</div>
</body>
</html>
<br />
<p><a href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!</p>
代码来自:http://www.webdm.cn/webcode/9537275b-f6b9-4da3-9a0d-45770c21bde3.html
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>让图片水平循环飞舞的JavaScript代码 - www.webdm.cn</title>
</head>
<body onload="next();">
<script language="JavaScript">
var pos1=-95;
var pos2=-95;
var pos3=-95;
var speed1 = Math.floor(Math.random()*10)+2;
var speed2 = Math.floor(Math.random()*10)+2;
var speed3 = Math.floor(Math.random()*10)+2;
function next() {
pos1 += speed1;
pos2 += speed2;
pos3 += speed3;
if (pos1 > 795) pos1 = -95;
if (pos2 > 795) pos2 = -95;
if (pos3 > 795) pos3 = -95;
if (document.layers) {
document.layers[0].left = pos1;
document.layers[1].left = pos2;
document.layers[2].left = pos3;
}
else {
mouse1.style.left = pos1;
mouse2.style.left = pos2;
mouse3.style.left = pos3;
}
window.setTimeout("next();",10);
}
</script>
<div id="mouse1"
style="HEIGHT: 100px; LEFT: 0px; POSITION: absolute; TOP: 165px; WIDTH: 100px">
<dd><img alt border="0" src="http://www.webdm.cn/images/wall1_s.jpg" width="80" height="70" /> </dd>
</div><div id="mouse2"
style="HEIGHT: 100px; LEFT: 0px; POSITION: absolute; TOP: 250px; WIDTH: 100px">
<dd><img alt border="0" src="http://www.webdm.cn/images/wall2_s.jpg" width="70" height="60" /></dd>
</div><div id="mouse3"
style="HEIGHT: 100px; LEFT: 0px; POSITION: absolute; TOP: 333px; WIDTH: 100px">
<dd><img alt border="0" src="http://www.webdm.cn/images/wall3_s.jpg" width="72" height="61" /></dd>
</div>
</body>
</html>
<br />
<p><a href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!</p>
代码来自:http://www.webdm.cn/webcode/9537275b-f6b9-4da3-9a0d-45770c21bde3.html