요소를 아래쪽 정렬하는 플러그인을 만들었습니다. 그것이 내가 이런 짓을 간단한 형태의에서 :jQuery를 사용하여 크로스 브라우저 요소의 높이를 어떻게 계산합니까?
- outerElement (DIV) 현재 요소의
- 가져 오기 높이의 가져 오기 높이
- 결과 = outerHeight - 현재 요소의 높이
- 정 CSS 속성 '최고'= 결과.
Firefox 및 IE8에서는 작동하지만 Opera 또는 Chrome에서는 작동하지 않습니다.
테두리, 패딩 및 여백과 관련이 있다고 생각합니다. 브라우저간에 상호 작동하려면 어떻게해야합니까?
업데이트
코드가 개정되어 현재 작업 중입니다.
(function($){
$.fn.alignBottom = function()
{
var defaults = {
outerHight: 0,
elementHeight: 0
};
var options = $.extend(defaults, options);
var bpHeight = 0; // Border + padding
return this.each(function()
{
options.outerHight = $(this).parent().outerHeight();
bpHeight = options.outerHight - $(this).parent().height();
options.elementHeight = $(this).outerHeight(true) + bpHeight;
$(this).css({'position':'relative','top':options.outerHight-(options.elementHeight)+'px'});
});
};
})(jQuery);
html로는 다음과 같이 볼 수 있습니다 :
div class="myOuterDiv">
<div class="floatLeft"> Variable content here </div>
<img class="bottomAlign floatRight" src="" /> </div>
</div>
을 내 jQuery 플러그인을 적용 :
jQuery(".bottomAlign").alignBottom();
스티븐, 당신이'position : absolute; 하단 : 0'? –
부모 요소의 크기가 가변적 일 때 작동하지 않기 때문입니다. – Steven