61,115
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
<style type="text/css">
html,body {
height: 100%;
margin: 0;
}
#d {
position: absolute;
left: 200px;
top: 200px;
width: 100px;
height: 100px;
background-color: #f99;
transform: translate(0px,0px);
transition: transform 500ms;
}
</style>
</head>
<body>
<div id="d"></div>
<script type="text/javascript">
document.onmousemove = function (e) {
e = e||window.event;
var x = 0.5-e.clientX/document.body.offsetWidth;
var y = 0.5-e.clientY/document.body.offsetHeight;
document.getElementById("d").style.transform = "translate("+x*100+"px,"+y*100+"px)";
};
</script>
</body>
</html>