来源网络并进行修改,不影响鼠标点击行为。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
img
{
position:fixed;
}
</style>
<script type="text/javascript">
var picture;
window.onload=function()
{
picture = document.getElementById("8picture");
window.onmousemove = onMove;
}
function onMove(event)
{
var x = event.clientX;
var y = event.clientY;
picture.style.top = y + "px";
picture.style.left = (parseInt(x)+10)+"px";
}
</script>
</head>
<body>
<img src="Img/1330721580922.gif" id="8picture" />
</body>
</html>
里面主要用到的样式是position:fixed;和事件参数对象
浏览器在调用事件方法时,会创建一个事件参数对象,并将其传入到事件方法中