鼠标跟随事件随笔!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>鼠标跟随事件</title>
<style>
body{
margin:0;
padding:0;
position: relative;
}
#follow{
position:absolute;
color:cornflowerblue;
}
</style>
</head>
<body>
<div id="follow">哈哈</div>
<script>
window.onload=function(){
var follow = document.getElementById("follow");
document.onmousemove = function(e){
var e = event || window.event
follow.style.left =e.clientX+ 10 +"px";//clientX 事件属性返回当事件被触发时鼠标指针向对于浏览器页面(或客户区)的水平坐标。
follow.style.top =e.clientY+ (-10) + "px";//clientY 事件属性返回当事件被触发时鼠标指针向对于浏览器页面(或客户区)的垂直坐标。
}
}
</script>
</body>
</html>