可滚动Div,可以看到哪些元素 [英] Scrollable Div, which elements can be seen

查看:183
本文介绍了可滚动Div,可以看到哪些元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个可滚动的div,它有CSS hieght:40px; 。里面是多个LI height:20px

We have a scrollable div that has CSS hieght:40px;. Inside it are multiple LI height:20px

    <div id="#scroller">
<li title="I1">item1</li>
<li title="I2">item2</li>
<li title="I3">item3</li>
<li title="I4">item4</li>
<li title="I5">item5</li>
<li title="I6">item6</li>
<li title="I7">item7</li>
<li title="I8">item8</li>
<li title="I9">item9</li>
    </div>

当用户滚动时,我想触发一个脚本来确定两个元素中的第一个是可见的。 div卷轴设计为捕捉到元素。所以如果你向下滚动,item3和item4是可见的,我如何资金出来的那个项目3是顶部可见的元素。

When the user scrolls I want to trigger a script that determines the first of the two elements which is visible. The div scroll is designed to snap to elements. So if you scroll down and item3 and item 4 are visible how do I fund out that item 3 is the top visible element.

我试过 $ ('#scroller li:visible'),但是这不工作,因为div关于他们都可见只是隐藏在他们的容器后面。

I tried $('#scroller li:visible') but this does not work as far as the div is concerned they are all visible just hidden behind their container.

任何想法,

奇妙

推荐答案

h2>

更新了工作示例 http://jsfiddle.net/U4qyp/32/

我认为 .position()工作。它给出了元素相对于其父元素的位置。在调用.position()之后,您可以使用属性 top left 来访问元素坐标。

I think .position() should do the job. It gives you the position of the element relative to its parent element. After you called .position() you can access the element coordinates using the properties top and left.

http://api.jquery.com/position/

顶部位置加上其高度大于零的元素是可见的。

The element whose top position plus its height is major than zero, is visible.

这里是我的意思。

http://jsfiddle.net/U4qyp/10/

这篇关于可滚动Div,可以看到哪些元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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