复制代码 代码如下:/* * Copyright (c) 2010 刘建华 * * The above copyright notice shall be * included in all copies or substantial portions of the Software. * Example: <div style="height:1000px">demo</div> <div id="demo" style="height:50px; background:purple; width:50px;z-index:999999; position:absolute;left:-1000px;top:-1000px;">demo</div> <script type="text/javascript" > var o = $(document); o.mousemove( function(e){ var d = document.getElementById("demo"); d.style.left = ($.mouse(e).left + 5) + "px"; d.style.top = ($.mouse(e).top + 5) + "px"; }); </script> */ /* * mouse Plugin for jQuery * Version: 1.0 * Release: 2010-03-30 */ (function($) { //Main Method jQuery.mouse = function(e){ var mouseleft = 0; var mousetop = 0; if(!($.browser.msie && /MSIEs(5.5|6.)/.test(navigator.userAgent))) { mouseleft=e.pageX; mousetop=e.pageY; } else { var _top = document.compatMode=="CSS1Compat" ? document.documentElement.scrollTop : document.body.scrollTop; var _left = document.compatMode=="CSS1Compat" ? document.documentElement.scrollLeft : document.body.scrollLeft; mouseleft=_left+event.clientX; mousetop=_top+event.clientY; } return {left:mouseleft,top:mousetop} ; }; })(jQuery);
推荐阅读
javascript 程序库的比较(一)之DOM功能
1,Prototype程序库 这是第一个把document.getElementById()简化为$的程序库。 比如:原来的var myele=document.getElementById('id')等价于var myele=$('id') 此外,$还扩展了一些功能 比如:var >>>详细阅读
本文标题:基于jquery的获取mouse坐标插件的实现代码
地址:http://www.17bianji.com/kaifa2/JS/26696.html
1/2 1