admin管理员组文章数量:1391964
I am using the Waypoints Jquery plugin:
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?
I am using the Waypoints Jquery plugin: http://imakewebthings.github./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?
Share Improve this question asked Oct 26, 2011 at 19:16 Adam McAdam Mc 751 silver badge5 bronze badges2 Answers
Reset to default 2That's what I did on my page:
var opts = {
offset: '110%',
context: '#central-pane .viewport-content'
};
$('#waypoint').waypoint(function(event, direction) {
alert("You've hit my waypoint! ow!");
$('#messages').append($loading);
if(direction === 'down') {
messagesLoad(); /* loads more messages via appendTo('#messages') */
}
$.waypoints('refresh');
}, opts);
I used 110% to trigger loading before the bottom is reached and checked if the direction is down.
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.
本文标签:
版权声明:本文标题:javascript - How do I get Waypoints (Jquery plugin) to work for infinite scroll in the following case? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744732664a2622143.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论