List of Counters Items shown on screen, not overflow

How to count all list items displayed on screen when overflow is set to hidden?

Using the code below, all elements, even those that overflow, are still counted.

var count = $("#myList ul li:visible").length; 

Violin:

http://jsfiddle.net/kPAwX/2/

+6
source share
1 answer
 var maxh = $("#myList ul").height(); $("#myList ul li").filter(function () { return $(this).position().top + $(this).height() < maxh; }); 

This will select all li that will be fully visible. If a li partially cut off, it will be filtered.

If you want even partially visible li not to be filtered out, just remove the height addition (or create your own slice in any way).

http://jsfiddle.net/ExplosionPIlls/z6GXA/

+5
source

All Articles