让div跟着鼠标移动


朋友求助帖

 

具体实现代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #rianley{
            width: 50px;
            height: 50px;
           background: red;
            position: absolute;
            left: 0;
            top: 0;
        }
    </style>
    <script>
        document.onmousemove=function(e){
            var rianley=document.getElementById("rianley");
            rianley.style.left=e.clientX+"px";
            rianley.style.top=e.clientY+"px";
        }
    </script>
</head>
<body>
    <div id="rianley"></div>
</body>
</html>

  

说明 

转载请注明出处

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM