• 【作业】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>
  • 相关阅读:
    初识sed和gwak
    USB驱动程序设计
    linux-usb软件系统架构
    CSS基础 布局
    CSS基础 样式属性
    CSS基础 样式分类、选择器
    HTML基础 页面效果(标题图标、锚点、插入音乐,视频、滚动效果、嵌入网页)
    HTML基础 常用标记
    HTML基础 表单
    HTML基础 初识 HTML(整体结构 文字 图片 表格 超链接)
  • 原文地址:https://www.cnblogs.com/dofstar/p/11570629.html
Copyright © 2020-2023  润新知