您的位置:首页 > 其它

div随鼠标移动

2015-11-04 13:44 274 查看
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#div1{
width:200px;
height: 300px;
background: #ccc;
position: absolute;
}

</style>
<script>
window.onload=function(){
document.onmousemove=function(ev){
var odiv=document.getElementById('div1');
var oevent=ev || event;
odiv.style.left=oevent.clientX+'px';
odiv.style.top=oevent.clientY+'px';
}
}
</script>
</head>
<body>
<div id="div1"></div>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: