Get full height of a clipped DIV

前端 未结 6 1059
小鲜肉
小鲜肉 2020-12-14 06:03

How do I get the height of the div which includes the clipped area of the div ?

content
conte
6条回答
  •  余生分开走
    2020-12-14 06:45

    Here is one way to achieve what you need, using Fabian idea:

    function GetHeight() {
        var oDiv = document.getElementById("MyDiv");
        var sOriginalOverflow = oDiv.style.overflow;
        var sOriginalHeight = oDiv.style.height;
        oDiv.style.overflow = "";
        oDiv.style.height = "";
        var height = oDiv.offsetHeight;
        oDiv.style.height = sOriginalHeight;
        oDiv.style.overflow = sOriginalOverflow;
        alert("Real height is " + height);
    }
    

    Live demo and test case: http://jsfiddle.net/yahavbr/7Lbz9/

提交回复
热议问题