当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Js实现div跟着鼠标移动的代码教程

Js实现div跟着鼠标移动的代码教程

2019年03月24日  | 移动技术网IT编程  | 我要评论

js实现p跟着鼠标移动的代码教程

html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #p1{
            width: 0;
            height: 0;
            border-left: 10px solid green;
            border-right: 10px solid red;
            border-top: 10px solid yellow;
            border-bottom: 10px solid blue;
            border-radius: 100px;
            position: absolute;
            left: 0;
            top: 0;
        }
    style>
    <script>
        document.onmousemove=function(e){
            var p=document.getelementbyid("p1");
            p.style.left=e.clientx+"px";
            p.style.top=e.clienty+"px";
        }
    script>
head>
<body>
    <p id="p1">p>
body>
html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网