首页 > 其他 > 详细

跟随鼠标的DIV和一连串跟随鼠标的DIV

时间:2015-12-24 20:40:12      阅读:211      评论:0      收藏:0      [点我收藏+]

1. 跟随鼠标的DIV

 1     window.onmousemove = function(ev) {
 2         //浏览器兼容
 3         var oEvent = ev || event;
 4         var oDiv = document.getElementById("div1");
 5 
 6         //页面滚动的距离
 7         var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
 8         var scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
 9         
10         oDiv.style.top = scrollTop + oEvent.clientY + "px";
11         oDiv.style.left = scrollLeft + oEvent.clientX + "px";
12     };

2. 一连串跟随鼠标的DIV

 1     window.onload = function() {
 2         var divs = document.getElementsByTagName("div");
 3 
 4         window.onmousemove = function(ev) {
 5             var oEvent = ev || event;
 6 
 7             for (var i = divs.length - 1; i > 0; i--) {
 8                 divs[i].style.left = divs[i - 1].style.left;
 9                 divs[i].style.top = divs[i - 1].style.top;
10             }
11 
12             divs[0].style.left = oEvent.clientX + "px";
13             divs[0].style.top = oEvent.clientY + "px";
14         }
15     };

 

跟随鼠标的DIV和一连串跟随鼠标的DIV

原文:http://www.cnblogs.com/HuoAA/p/5074184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!