如何知道用户何时滚动经过?
我正在构建一些东西,向用户展示他们没有见过的物品。
每个项目都在
中,因此当用户滚动经过 div 或查看该 div 时,我希望将该项目标记为已查看。谷歌阅读器就是这样做的,如果你滚动浏览提要中的某个项目,它会自动将其标记为已读。
如何追踪这一点?请指教。
注意:不应该仅限于使用鼠标滚动,向下/向上翻页,使用箭头键等也应该计算在内。主要标准是用户已经看到了 div。
I'm building something where I show users items that they haven't seen.
Each item is in a <div>
, so when the user scrolls past a div, or views the div, I want that item to be marked as having been seen.
Google reader does this, if you scroll past an item in your feed there it automatically marks it as read.
How can this be tracked? Advice please.
Note: It shouldn't be restricted to using the mouse to scroll, hitting page down/up, using arrow keys, etc should also be counted. The main criteria is that the user has seen a div.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要 jQuery 的
scrollTop
。例如:
当它第一次进入视图时,或者如果您希望它在完全视图中时被标记,则将
$('#mydiv').height()
添加到顶部偏移量。You need jQuery's
scrollTop
.Something like:
for when it first comes into view, or add
$('#mydiv').height()
to the top offset if you want it to be marked when it's fully in view.您可以使用这样的解决方案,http://www.appelsiini.net/projects/viewport,我以前用过。
或者查看其他解决方案:检测窗口中呈现的 div 以实现类似 Google Reader 的自动标记为已读?
You could use a solution like this, http://www.appelsiini.net/projects/viewport, which I used in the past.
Or see this for other solutions: Detecting divs as rendered in the window to implement Google-Reader-like auto-mark-as-read?
看看
$("#divid").scrollTop()
。Have a look at
$("#divid").scrollTop()
.我想你会需要这样的东西......
I think you'll need something like this...