DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> 基於jquery的獲取mouse坐標插件的實現代碼
基於jquery的獲取mouse坐標插件的實現代碼
編輯:JQuery特效代碼     

代碼如下:
/*
* 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 && /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);

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved