jQuery: How to get content not visible with overflow: hidden?

后端 未结 1 1817
独厮守ぢ
独厮守ぢ 2021-01-01 07:14

I\'m trying to span content across multiple pages (divs) set at a height of 950px per div, so I can properly output to pdf.

I start off with one div which nests all

相关标签:
1条回答
  • 2021-01-01 07:52

    You need to compare the position of each element to the height of the document (body):

    if ($("#elementOne").position().top > $("body").height()){
        // This element is hidden
    }
    

    This example scans each element and builds an array of elements that are hidden (completely):

    var h = $("body").height();
    var hiddenEls = new Array();
    
    $("#container").find("*").each(function(){
        if ($(this).position().top > h)
            hiddenEls.push($(this));
    });
    

    Please note that this is untested.

    Try this example:

    http://jsfiddle.net/wMPjJ/

    A blue container is set to 400px in height, with the overflow hidden. In the div, there are 22 p elements, numbered from 1 - 22. Some will be hidden (they don't fit). The code on the page will tell you how many elements are hidden (for me, I get 5; p tags 17 through 22 don't show up)

    0 讨论(0)
提交回复
热议问题