在以下情况下,如何让 Waypoints(Jquery 插件)用于无限滚动?
我正在使用 Waypoints Jquery 插件: http://imakewebthings.github.com/jquery-waypoints/ #documentation
我的问题是我想在到达路径点时动态加载内容。最初,内容是动态加载的,然后我想要最后的路点...当到达路点时,我想在它前面加载更多内容,等等。
结构:
<div class="viewport">
<div class="viewport-content">
<div id="messages">
/* {messages loaded here} */
</div>
/* #waypoint added after messages loaded via appendTo('.viewport-content') */
<div id="waypoint"></div>
</div>
</div>
视口/视口内容通过以下形式形成可滚动区域CSS。我在加载初始消息后使用appendTo附加航路点,否则航路点位于顶部并被击中。但是,当我在加载初始消息后使用appendTo时,当我向下滚动时,我无法让它正常工作。
这是我当前关于路径点的 JS:
var opts = {
offset: 'bottom-in-view',
context: '#central-pane .viewport-content',
};
$('#waypoint').waypoint(function(event, direction) {
alert("You've hit my waypoint! ow!");
$('#messages').append($loading);
messagesLoad(); /* loads more messages via appendTo('#messages') */
$('#waypoint').waypoint(opts);
}, opts);
关于如何让它工作的任何想法?
I am using the Waypoints Jquery plugin: http://imakewebthings.github.com/jquery-waypoints/#documentation
My issue is that I want to load content dynamically when the waypoint is reached. Initially, content is loaded dynamically, then I want the waypoint at the end... when the waypoint is reached, I want to load more content in front of it, etc.
Structure:
<div class="viewport">
<div class="viewport-content">
<div id="messages">
/* {messages loaded here} */
</div>
/* #waypoint added after messages loaded via appendTo('.viewport-content') */
<div id="waypoint"></div>
</div>
</div>
The viewport/viewport-content form the scrollable region via css. I was using the appendTo to append the waypoint after the initial messages had loaded, otherwise the waypoint was at the top and was hit. However, when I use the appendTo after loading the initial messages, when I scroll down, I can't get it to work properly.
Here is my current JS in regards to the waypoint:
var opts = {
offset: 'bottom-in-view',
context: '#central-pane .viewport-content',
};
$('#waypoint').waypoint(function(event, direction) {
alert("You've hit my waypoint! ow!");
$('#messages').append($loading);
messagesLoad(); /* loads more messages via appendTo('#messages') */
$('#waypoint').waypoint(opts);
}, opts);
Any ideas on how I can get this to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我在页面上所做的:
在到达底部之前我使用 110% 来触发加载,并检查方向是否向下。
That's what I did on my page:
I used 110% to trigger loading before the bottom is reached and checked if the direction is down.
为什么不将路径点附加到“.viewport-content”并保留“bottom-in-view”选项。这样,当内容加载时,它将底部推到视图之外,当您向下滚动更多时,当底部回到视图中时,它将再次触发该事件。
Why don't you just attach the waypoint to the ".viewport-content" and keep the "bottom-in-view" option. That way when the content gets loaded it pushes the bottom out of view and when you scroll down more it will fire the event again when the bottom is back in view.