2011-09-22 2 views
1

IE7에서 div의 높이를 읽으려고합니다. Element.currentStyle은 "auto"를 반환합니다. 이 요소의 높이를 어떻게 계산합니까? jQuery는 어떻게이 작업을 수행합니까? 그것의 height() 함수는 값 (http://api.jquery.com/height/)을 검색 할 수 있습니다. IE 개발자의 막대가 값이 auto로 설정된 것을 보여줄 때입니까?"auto"가 반환 될 때 IE7에서 CSS 값을 얻는 방법

편집 : 나는 jQuery를 사용하지 않는, 그래서 어쩌면 순수 자바 스크립트

document.getElementById("idHere").offsetHeight 작품을
+0

http://stackoverflow.com/questions/692523/getting-actual-height-of-an-auto-heighted-element-in -ie – JamesHalsall

답변

1

을이 작업을 수행 솔루션을 바라고 있어요!

+0

감사합니다! 이것은 내가 찾고 있던 대답이다. – Mansiemans

0

내가이 계산 jQuery를 기능이라고 생각 높이 :

function getWH(elem, name, extra) { 

    // Start with offset property 
    var val = name === "width" ? elem.offsetWidth : elem.offsetHeight, 
     which = name === "width" ? cssWidth : cssHeight; 

    if (val > 0) { 
     if (extra !== "border") { 
      jQuery.each(which, function() { 
       if (!extra) { 
        val -= parseFloat(jQuery.css(elem, "padding" + this)) || 0; 
       } 
       if (extra === "margin") { 
        val += parseFloat(jQuery.css(elem, extra + this)) || 0; 
       } else { 
        val -= parseFloat(jQuery.css(elem, "border" + this + "Width")) || 0; 
       } 
      }); 
     } 

     return val + "px"; 
    } 

    // Fall back to computed then uncomputed css if necessary 
    val = curCSS(elem, name, name); 
    if (val < 0 || val == null) { 
     val = elem.style[ name ] || 0; 
    } 
    // Normalize "", auto, and prepare for extra 
    val = parseFloat(val) || 0; 

    // Add padding, border, margin 
    if (extra) { 
     jQuery.each(which, function() { 
      val += parseFloat(jQuery.css(elem, "padding" + this)) || 0; 
      if (extra !== "padding") { 
       val += parseFloat(jQuery.css(elem, "border" + this + "Width")) || 0; 
      } 
      if (extra === "margin") { 
       val += parseFloat(jQuery.css(elem, extra + this)) || 0; 
      } 
     }); 
    } 

    return val + "px"; 
} 
관련 문제