图片跟随鼠标移动特效
Posted yaoliuyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图片跟随鼠标移动特效相关的知识,希望对你有一定的参考价值。
鼠标移入空白区域查看效果:
2.上代码演示
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}
#move {
position: absolute;
left: -300px;
top: -300px;
}
</style>
<body>
<img id="move" src="https://i.loli.net/2020/04/18/OXz4M1h5VcxKCU3.png">
</body>
<script type="text/javascript">
var move = document.getElementById(‘move‘);
window.onmousemove = function(e) {
var event = e || window.event;
var x = event.clientX;
var y = event.clientY;
if (x <= 10 || y <= 10||x>(document.body.clientWidth-move.offsetWidth)) {
x = -300;
}
move.style.left = x + "px";
move.style.top = y + "px";
}
</script>
</html>
以上是关于图片跟随鼠标移动特效的主要内容,如果未能解决你的问题,请参考以下文章
Ant Design -- 图片可拖拽效果,图片跟随鼠标移动