jquery获取mouse坐标插件

/*
 * Copyright (c) 2010 刘建华 (xmjiahua.com 258420235@qq.com)
 *
 * 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 && /MSIE\s(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);

posted @ 2010-03-30 16:49  zzljh  阅读(1111)  评论(0编辑  收藏  举报