zoukankan      html  css  js  c++  java
  • 鼠标跟随

    实现一个简单的鼠标跟随效果。

    代码如下

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>鼠标跟随</title>
    </head>
    <style type="text/css">
        #gen{
            width: 50px; height: 50px; background-color: #2fa; padding: 20px; position: absolute; color: #fff; text-align: center; 
        }
    </style>
    <body>
        <div id="gen">
            鼠标跟随
        </div>
        <script type="text/javascript">
            window.onmousemove = function(event){
                var oTop = document.getElementById("gen");
                var e = event || window.event;
                var scrollleft = document.documentElement.scorllLeft || document.body.scrollLeft;
                var scrolltop = document.documentElement.scorllTop || document.body.scrollTop;
                var x = e.clientX;
                var y = e.clientY;
                oTop.style.left = x + scrollleft + "px";
                oTop.style.top = y + scrolltop + "px";
            }
        </script>
    </body>
    </html>
  • 相关阅读:
    java中的Set的使用以及各种遍历方法(较为全面)
    系统图标
    监听按钮
    GUI
    【Avalon】获取隐藏元素的尺寸
    Hooks
    特性节点Attribute
    ngCloak
    邮件
    时间
  • 原文地址:https://www.cnblogs.com/hu555snow/p/5706743.html
Copyright © 2011-2022 走看看