码迷,mamicode.com
首页 > 移动开发 > 详细

随鼠标移动

时间:2017-03-09 13:24:14      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:lang   set   abs   style   鼠标移动   har   doc   absolute   doctype   

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<span id="a" style="position:absolute;border: 1px solid blue">
    跟着我
</span>
<script>
    function a(){
        var div = document.getElementById("a");
        if (!div) {
            return;
        }
        var intX = window.event.clientX;
        var intY = window.event.clientY;
        div.style.left = intX + "px";
        div.style.top = intY + "px";
    }
    document.onmousemove = a;
</script>
</body>
</html>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
<span id="a" style="border: 1px solid blue">
    跟着我
</span>
<script>
    function a(){
        var div = document.getElementById("a");
        div.style.position=‘absolute‘;
        div.style.left = window.event.clientX+ "px";
        div.style.top =window.event.clientY+ "px";
    }
    document.onmousemove = a;
</script>
</body>
</html>

 超简单版的跟着鼠标移动

随鼠标移动

标签:lang   set   abs   style   鼠标移动   har   doc   absolute   doctype   

原文地址:http://www.cnblogs.com/zxy945/p/6524945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!