计数列表项目显示在屏幕上且不会溢出 [英] Count List Items shown on screen and not overflow

查看:101
本文介绍了计数列表项目显示在屏幕上且不会溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当溢出设置为隐藏时,如何计算屏幕上显示的所有列表项?

How can I count all the list items that are displayed on the screen when overflow is set to hidden?

使用下面的代码仍会计算所有项目,即使是溢出的项目也是如此.

Using the code below still counts all the items, even the ones that overflow.

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

提琴:

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

推荐答案

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

这将选择所有完全可见的li.如果li被部分切除,它将被过滤.

This will select all of the lis that are completely visible. If an li is partially cut off, it will be filtered.

如果您甚至不希望滤除部分可见的li,只需删除高度的增加(或以任何想要的方式创建自己的边界).

If you want even partially visible lis to not be filtered, simply remove the addition of the height (or create your own cut off any way you want).

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

这篇关于计数列表项目显示在屏幕上且不会溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆