Get height of non-overflowed portion of div

后端 未结 5 1752
[愿得一人]
[愿得一人] 2020-12-16 01:34

Say I have a wrapper div with a overflow:hidden on it and a div inside that that spans far below the visible portion. How can I get the visible height of the in

5条回答
  •  既然无缘
    2020-12-16 02:19

    As basic algorithm this could work:

    var offset = 0;
    var node = document.getElementById("inner");
    while (node.offsetParent && node.offsetParent.id != "wrapper")
    {
        offset += node.offsetTop;
        node = node.offsetParent;
    }
    var visible = node.offsetHeight - offset;
    

    But if you're doing these kinds of things, maybe you already use jQuery, which might be of service with its .height() and .offset() functions:

    $("#wrapper").height()-
    $("#inner").offset()['top']+
    $("#wrapper").offset()['top'];  
    

提交回复
热议问题