码迷,mamicode.com
首页 > 移动开发 > 详细

图片跟随鼠标移动特效

时间:2020-04-18 23:05:45      阅读:106      评论:0      收藏:0      [点我收藏+]

标签:png   utf-8   html   offset   def   theme   set   win   body   

鼠标移入空白区域查看效果:

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>

图片跟随鼠标移动特效

标签:png   utf-8   html   offset   def   theme   set   win   body   

原文地址:https://www.cnblogs.com/yaoliuyang/p/12728588.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!