jQuery:滚动某个类的div时运行 [英] jQuery: Run when scroll over a div of a certain class

查看:95
本文介绍了jQuery:滚动某个类的div时运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有多个相同类别的div。我现在想每次访问者滚动到一个新的div时触发一个加载评论功能。不过,我不知道如何跟踪jQuery滚动div。每个div的注释只能加载一次,我的想法是将当前位置保存在一个变量中,并且只在新滚动位置大于旧滚动位置时才加载注释。



你可以请我帮忙吗?

编辑:我创建了一张图片,显示我需要做什么。
图片: http://i.imgur.com/78EYK.jpg p>

编辑2:已解决!
用Viewport解决(感谢Royi Namir)
http://www.appelsiini。 net / projects / viewport



我的代码:

  load = $(。my-div:in-viewport)。attr('id'); 
load_comments(load);

每秒执行一次。

解决方案

您应阅读有关视口



Viewport将多个额外选择器添加到jQuery中。通过这些选择器,您可以检查元素是在视口内还是在视口之外。看看它是如何工作的检查演示。



http://www.appelsiini.net/projects/viewport/3x2.html


so I have multiple divs of the same class below each other. I now want to trigger a "loading comments"-function every time a visitor scrolls to a new div. However, I have no idea how to track jQuery scroll over a div. The comments for each div should only be loaded once, my idea would be to save the current position in a variable and only load comments when the new scroll position is greater than the old one.

Can you please help me out?

EDIT: I created a image that shows what I need to do. Image: http://i.imgur.com/78EYK.jpg

EDIT 2: SOLVED! Solved with Viewport (thanks to Royi Namir) http://www.appelsiini.net/projects/viewport

My code:

load = $(".my-div:in-viewport").attr('id');
load_comments(load);

This is executed every second.

解决方案

you should read about viewport

Viewport ads couple of extra selectors to jQuery. With these selectors you can check whether element is inside or outside of viewport. To see how it works check the demo.

http://www.appelsiini.net/projects/viewport/3x2.html

这篇关于jQuery:滚动某个类的div时运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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