jQuery:滚动某个类的div时运行 [英] jQuery: Run when scroll over a div of a certain class
问题描述
你可以请我帮忙吗?
编辑:我创建了一张图片,显示我需要做什么。
图片: 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屋!