JQuery 플러그인 25번째: 네트워크에서 html 컨트롤을 가져오는 절대 위치를 개편합니다

2322 단어
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title >JQuery : html </title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script type="text/javascript" language="javascript" src="../jquery-1.6.js" ></script>
</head>
<body>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
         
<button id="dd" type="button" value=""   > </button>
<script language="javascript" type="text/javascript" >
(function ($) { 
jQuery.fn.getAbsLocation=function() {  
    var tempArr=[];
    this.each(function(){
        var elmt = this;   
        var offsetTop = elmt.offsetTop;   
        var offsetLeft = elmt.offsetLeft;   
        var offsetHeight = elmt.offsetHeight; 
        var offsetWidth=elmt.offsetWidth;
        while (elmt = elmt.offsetParent) {   
            // add this judge   
            if (elmt.style.position == 'absolute'|| elmt.style.position == 'relative'||(elmt.style.overflow != 'visible' && elmt.style.overflow != '')) {   
               break;   
            }   
             offsetTop += elmt.offsetTop;   
             offsetLeft += elmt.offsetLeft;   
        }
        tempArr[tempArr.length]={ Top: offsetTop, Left: offsetLeft, Width: offsetWidth, Height: offsetHeight };   
    });
    return tempArr;
}
})(jQuery);
	var result=$("#dd").getAbsLocation();
	alert(result[0].Left);
	alert(result[0].Top);
	alert(result[0].Width);
	alert(result[0].Height);
	
	alert($("#dd").offset().top);
	alert($("#dd").offset().left);
	alert($("#dd").width());
	alert($("#dd").height());
</script>
</body>
</html>

좋은 웹페이지 즐겨찾기