首页 > 代码库 > 图片随鼠标移动

图片随鼠标移动

<head>
<title></title>

<script type="text/javascript">
        document.onmousemove =function() {        //当鼠标移动式获取当前x,y坐标值
var x = window.event.clientX;
var y = window.event.clientY;
var f = document.getElementById("fly");        //取到id为fly的标签内容赋值于f
if (!f) {                                //如果没有取到,则返回
return;
            }
            f.style.left = x;                        //否则将f的坐标设为鼠标坐标值x,y
            f.style.top = y;
        }
</script>

</head>
<body>
<div id="fly" style="position: absolute">
<img src="300png016.png"/><br />
哈哈!我会飞!
</div>
</body>