mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
Fix $(...).offset() is undefined
on some scrolls.
This commit is contained in:
parent
8d21f6f074
commit
a17f1247a8
|
@ -355,8 +355,21 @@ export default class PostStream extends Component {
|
||||||
this.updateScrubber();
|
this.updateScrubber();
|
||||||
const index = $item.data('index');
|
const index = $item.data('index');
|
||||||
m.redraw.sync();
|
m.redraw.sync();
|
||||||
const scroll = index == 0 ? 0 : $(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop();
|
|
||||||
$(window).scrollTop(scroll);
|
// After post data has been loaded in, we will attempt to scroll back
|
||||||
|
// to the top of the requested post (or to the top of the page if the
|
||||||
|
// first post was requested). In some cases, we may have scrolled to
|
||||||
|
// the end of the available post range, in which case, the next range
|
||||||
|
// of posts will be loaded in. However, in those cases, the post we
|
||||||
|
// requested won't exist, so scrolling to it would cause an error.
|
||||||
|
// Accordingly, we start by checking that it's offset is defined.
|
||||||
|
const offset = $(`.PostStream-item[data-index=${index}]`).offset();
|
||||||
|
if (index === 0) {
|
||||||
|
$(window).scrollTop(0);
|
||||||
|
} else if (offset) {
|
||||||
|
$(window).scrollTop($(`.PostStream-item[data-index=${index}]`).offset().top - this.getMarginTop());
|
||||||
|
}
|
||||||
|
|
||||||
this.calculatePosition();
|
this.calculatePosition();
|
||||||
this.stream.paused = false;
|
this.stream.paused = false;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user