zoukankan      html  css  js  c++  java
  • 让图片水平循环飞舞的JavaScript代码

    代码简介:

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

    代码内容:

    View Code
    <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><href="http://www.webdm.cn">网页代码站</a> - 最专业的网页代码下载网站 - 致力为中国站长提供有质量的网页代码!</p>
    代码来自:http://www.webdm.cn/webcode/9537275b-f6b9-4da3-9a0d-45770c21bde3.html
  • 相关阅读:
    springaopxml
    【Cocos2dhtml5】解析例子中的飞机游戏(一)
    springiocannotation
    模板方法设计模式(JDBCTeampleta
    springaopannotation
    从前,有座山,山里有座庙,庙里有苦逼IT
    day 41 Nginx进阶
    day 42 作业
    day43 LNMP单机环境安装
    day 42 nginx rewrite跳转
  • 原文地址:https://www.cnblogs.com/webdm/p/2172325.html
Copyright © 2011-2022 走看看