js 小野人跟着鼠标移动

<!DOCTYPE html>


<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <script>
        onload = function () {
            onmousemove = function (e) {
                var img = document.getElementById('img');
                img.style.position = 'absolute';
                img.style.left = e.clientX + 'px';//记得加px
                img.style.top = e.clientY + 'px';

            }
        }
    </script>
</head>
<body>
    <img src="idle.png" id="img"/>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/dxm809/article/details/80263538