<title>案例分析:图片跟随鼠标</title>
<style>
img {
position: absolute;
top: 0px;
left: 0px;
}
</style>
</head>
<body>
<img src="第三章/images/猫.jpg" alt="">
<script>
// 1. 获取元素
let pic = document.querySelector('img');
document.addEventListener('mousemove', function(e) {
let x = e.pageX;
let y = e.pageY;
pic.style.top = x - 80 / 2 + 'px';
pic.style.left = y - 96 / 2 + 'px';
})
</script>
</body>
</html>
案例分析:图片跟随鼠标