Home >Web Front-end >JS Tutorial >JS small case: the follower who can't get rid of

JS small case: the follower who can't get rid of

不言
不言Original
2018-04-10 14:31:281925browse

This article mainly introduces the following JS cases that cannot be shaken off. Friends in need can refer to it

<br>

根本鼠标的XY值,让元素移动
<body>
    <img src="image/toux.ico" id="imgbug" alt="移动图片"></body>

<script type="text/javascript">
    window.onload = function () {
            var ima = document.getElementById("imgbug");
                    ima.style.position = "absolute";//让图片绝对定位
     //注册鼠标的移动处理函数
       document.onmousemove = function () {
        //改变图片的坐标
                    //获取鼠标的坐标
    var x = event.clientX;
                var y = event.clientY;
                            ima.style.left = x-ima.offsetWidth+"px";
                                        ima.style.top = y - 76+"px";
        }
    }</script>
<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>#

The above is the detailed content of JS small case: the follower who can't get rid of. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn