• 图片跟着鼠标移动


    <!DOCTYPE html>
    <html>
    <head>
    <title>duisgf</title>
    <meta charset="utf-8">
    <style type="text/css">
    #image{
    position: relative;
    left: 0px;
    top: 0px;
    }
    </style>
    </head>
    <body>
    <div>
    <img src="flowers.jpg" id="image">
    </div>
    </body>
    </html>
    <script type="text/javascript">
    var img = document.getElementById("image");
    document.onclick = function(event){
    var event = event || window.event;
    targetX =event.clientX - img.offsetWidth/2;
    targetY = event.clientY - img.offsetHeight/2;
    }

    var leaderX=0;
    leaderY=0;
    targetX=0;
    targetY=0;
    setInterval(function(){
    leaderX = leaderX + (targetX - leaderX)/10;
    leaderY = leaderY + (targetY - leaderY)/10;

    img.style.left = leaderX+"px";
    img.style.top = leaderY + "px";
    },10)
    </script>

    转载  http://www.cnblogs.com/yzybc/p/5781448.html

  • 相关阅读:
    UVA 221
    A Typical Homework(学生信息管理系统)
    追踪电子表格中的单元格
    浮点数!!!(摘)
    poj 3158kickdown
    循环小数 UVa202
    Unix is 命令
    W
    V
    完美世界 字符串倒置输出
  • 原文地址:https://www.cnblogs.com/li-guo-ping/p/5783074.html
Copyright © 2020-2023  润新知