js效果 div跟随鼠标移动
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<style>
*{
margin: 0;
padding: 0;
}
.div{
width: 200px;
height: 200px;
background: red;
position: absolute;
cursor: pointer;
}
</style>
<body>
<div class="div"></div>
</div>
</body>
<script>
var div=document.querySelector('.div');
window.onmousemove=function(evt){
var x=evt.clientX;
var y=evt.clientY;
x=x-div.offsetWidth/2;
y=y-div.offsetHeight/2;
div.style.left=x+'px';
div.style.top=y+'px';
}
</script>
</html>