首页 >web前端 >js教程 >Js鼠标跟随代码小手点击实例方法_javascript技巧

Js鼠标跟随代码小手点击实例方法_javascript技巧

WBOY
WBOY原创
2016-05-16 17:33:411468浏览

[Ctrl A 全选 注:如需引入外部Js需刷新才能执行
]<script> window.onload = function(){ var oCursor = document.getElementById("cursor"); document.onmousemove=function (ev){ var oEvent=ev||event, oWidth = document.documentElement.clientWidth, oHeight = document.documentElement.clientHeight, scrollTop=document.documentElement.scrollTop + oEvent.clientY, scrollLeft=document.documentElement.scrollLeft + oEvent.clientX; if(scrollTop > oHeight-oCursor.offsetHeight){ oCursor.style.top = oHeight-oCursor.offsetHeight+'px'; }else if(scrollTop < 0){ oCursor.style.top = 0; }else{ oCursor.style.top = scrollTop+'px'; } if(scrollLeft > oWidth-oCursor.offsetWidth){ oCursor.style.left = oWidth-oCursor.offsetWidth+'px'; }else{ oCursor.style.left = scrollLeft+'px'; } document.onmousedown = function(){ oCursor.innerHTML = "<img src='http://www.jb51.net/jscss/demoimg/201305/cursor_hover.png' / alt="Js鼠标跟随代码小手点击实例方法_javascript技巧" >"; return false; } document.onmouseup = function(){ oCursor.innerHTML = "<img src='http://www.jb51.net/jscss/demoimg/201305/cursor.png' / alt="Js鼠标跟随代码小手点击实例方法_javascript技巧" >"; } }; } </script>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn