js图片随鼠标移动案例
<style>
img{
width: 60px;
position: absolute;
transform: translate(-50% , -50%);
}
</style>
<img src="img/leimu.png" alt="">
<script>
var pic = document.querySelector('img');
document.addEventListener('mousemove', function(e){
var x = e.pageX;
var y = e.pageY;
console.log('x:' + x, 'y:' + y);
pic.style.left = x + 'px';
pic.style.top = y + 'px';
})
</script>
转载请注明原文地址:https://ipadbbs.8miu.com/read-1643.html