zoukankan      html  css  js  c++  java
  • 简单的移动

    bbbbb


    代码
    <style type="text/css">
    div
    {border:1px solid #ccc;}
    #a
    {width:500px;height:500px;position:relative;}
    #b
    {width:100px;height:100px;position:absolute;}
    </style>
    <script type="text/javascript">
    function movelement(elementId, final_x, final_y, interval){
    if(!document.getElementById(elementId)){ return false; }
    var element = document.getElementById(elementId);
    if(!element.style.top){
    element.style.top
    = 0;
    }
    if(!element.style.left){
    element.style.left
    = 0;
    }
    xpos
    = parseInt(element.style.top);
    ypos
    = parseInt(element.style.left);
    if(xpos == final_x && ypos == final_y){
    return true;
    }
    if(xpos < final_x){
    var dlist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dlist;
    }
    if(xpos > final_x){
    var dlist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dlist;
    }
    if(ypos < final_y){
    var dlist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dlist;
    }
    if(ypos > final_y){
    var dlist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dlist;
    }

    element.style.top
    = xpos + "px";
    element.style.left
    = ypos + "px";

    var repeat = "movelement('" + elementId + "'," + final_x + "," + final_y + "," + interval + ")";
    var mov = setTimeout(repeat, 20);
    }
    </script>
    </head>


    <div id="a">
    <div id="b">bbbbb</div>
    </div>
    <script type="text/javascript">
    movelement(
    "b", 200, 200, 20);
    </script>

  • 相关阅读:
    Gengxin讲STL系列——Set
    理解Python的With语句
    Python中Non-ASCII character 'xe7' in file的问题解决
    gnome-terminal的一些调整
    硬盘的CHS寻址
    Wiz发布cnblog笔记
    cygwin安装man手册
    linux命令行使用
    小步前进
    学习的感觉真好
  • 原文地址:https://www.cnblogs.com/jikey/p/1711792.html
Copyright © 2011-2022 走看看