[英]Reverse infinity scroll
我想制作信使,信息在聊天中显示,从下到上滚动。 当您滚动到限制的顶部时,系统将加载更多消息。
加载新项目后scrollTop
控件位置的问题。 怎么算这个位置?
HTML
<template name='chatBox'>
<div class='chat-box'><!--viewport-->
{{> chatBoxItem}}
{{/each}}
</div>
</template>
<template name='chatBoxItem'>
<div class='chat-box-wrapper'><!--content block-->
{{#each messeges}}
<p>{{messege}}</p> <!--each messege-->
{{/each}}
</div>
</template>
JS
Template.chatBox.onRendered(function() {
// viewport template
$('.chat-box').scroll(function(e) {
var chatBoxHeight = $('.chat-box').innerHeight();
var wrapperHeight = $('#chat-box-wrapper').innerHeight();
var chatBoxScroll = $('.chat-box').scrollTop();
var currentScrollFromBottom = wrapperHeight - chatBoxScroll; //don't sure if this formula is correct but it's count how many pixels was scrolled from bottom to top
if (currentScrollFromBottom == wrapperHeight && MESSAGES_LIMIT < amountOfMessages) {
//here some code to increase limit of queue
}
});
Template.chatBoxItem.onRendered(function () {
// content template
var $heightOfBlock = $('#chat-box-wrapper').height();
$('.chat-box').scrollTop($heightOfBlock);
// Here I have the most problem,
// I need to scroll to bottom when page is load (work good)
// but after loaded new items, it's need to stand still, but
// it's not. I don't know which formula i need
// to use to count current scroll position
});
也许这个例子完全错了,但我不明白如何反向制作无限滚动 - 从下到上。
更新:
我找到了这个公式,但这是为了正常滚动,我需要如何为反向滚动重建它?
$(window).scrollTop() + $(window).height() > $(document).height() - 100
我用jquery解决了这个问题:
var st=$("#chat").scrollTop();
$("#chat").prepend(me);
$("#chat").scrollTop(st+me.outerHeight());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.