mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 14:20:47 +08:00
Fix jumpy downward post loading
This commit is contained in:
parent
199bbcf5d4
commit
d053b5760e
|
@ -77,13 +77,16 @@ export default Ember.Component.extend({
|
|||
return false;
|
||||
}
|
||||
|
||||
// If new posts are being loaded in an upwards direction, then when they
|
||||
// are rendered, the rest of the posts will be pushed down the page.
|
||||
// However, we want to maintain the current scroll position relative to
|
||||
// the content after the gap. To do this, we need to find item directly
|
||||
// after the gap and use it as an anchor.
|
||||
if (this.get('direction') === 'up') {
|
||||
var anchor = this.$().nextAll('.item:first');
|
||||
// If new posts are being loaded in an upwards direction, then when
|
||||
// they are rendered, the rest of the posts will be pushed down the
|
||||
// page. If loaded in a downwards direction from the end of a
|
||||
// discussion, the terminal gap will disappear and the page will
|
||||
// scroll up a bit before the new posts are rendered. In order to
|
||||
// maintain the current scroll position relative to the content
|
||||
// before/after the gap, we need to find item directly after the gap
|
||||
// and use it as an anchor.
|
||||
var siblingFunc = this.get('direction') === 'up' ? 'nextAll' : 'prevAll';
|
||||
var anchor = this.$()[siblingFunc]('.item:first');
|
||||
|
||||
// Immediately after the posts have been loaded (but before they
|
||||
// have been rendered,) we want to grab the distance from the top of
|
||||
|
@ -102,7 +105,6 @@ export default Ember.Component.extend({
|
|||
$('body').scrollTop(anchor.length ? anchor.offset().top - scrollOffset : $('body').height());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Tell the controller that we want to load the range of posts that this
|
||||
// gap represents. We also specify which direction we want to load the
|
||||
|
|
Loading…
Reference in New Issue
Block a user