zoukankan      html  css  js  c++  java
  • 【作业】js动态移动图片

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/new_file.css" />
    <script type="text/javascript" src="js/new_file.js" ></script>
    <title></title>
    </head>
    <body>
    <div id="mapDiv" style="position: absolute;top: 100px;left: 200px; 800px;height: 600px;border: 1px solid red;text-align: center;">
    <input type="button" value="start" id = "st" />
    <div id="t" style=' 50px; background:url(img/t1.png);height: 48px;position: relative;left: 0px;background-size: 50px auto;top: 100px;'></div>
    <div id="r" style=' 50px; background:url(img/t1.png);height: 48px;position: relative;left: 0px;background-size: 50px auto;top: 200px;'></div>
    </div>
    </body>
    <script type="text/javascript">
    var array = [["img/t1.png","img/t3.png","img/t6.png"]];
    var intervalInstance = -1;
    i = 0;
    
    function start()
    {
    tObj = document.getElementById("t");
    rObj = document.getElementById("r");
    intervalInstance = setInterval(move,100);
    
    }
    
    function move()
    {
    tl = parseInt(tObj.style.left.split("px")[0]);
    rl = parseInt(rObj.style.left.split("px")[0]);
    if(rl<=725)i=(i+1)%3
    else
    {
    clearInterval(intervalInstance);
    return;
    }
    tObj.style.left = (tl+10) + "px";
    tObj.style.backgroundImage = "url("+array[0][i]+")";
    rObj.style.left = (rl+25) + "px";
    rObj.style.backgroundImage = "url("+array[0][i]+")";
    }
    
    window.onload = function()
    {
    document.getElementById("st").onclick = start;
    }
    </script>
    </html>
  • 相关阅读:
    词法分析程序
    关于编译原理
    超神c语言文法
    linux基本命令
    用bat来注册ocx
    当web配置文件 appSettings配置的东西越来越多时,可以拆开了。
    MVC的URL路由规则
    ASP.NET MVC 中如何实现基于角色的权限控制
    查cc攻击
    关于session介绍
  • 原文地址:https://www.cnblogs.com/dofstar/p/11570629.html
Copyright © 2011-2022 走看看