[bugfix] compatible <body /> is the scene of the scrolling container (#3844)

This commit is contained in:
流采
2019-07-15 19:36:21 +08:00
committed by neverland
parent dbe56fd362
commit 511087bc74
6 changed files with 40 additions and 18 deletions

View File

@@ -7,6 +7,7 @@ import {
getScrollTop,
getElementTop,
getRootScrollTop,
setRootScrollTop,
getScrollEventTarget
} from '../utils/dom/scroll';
@@ -77,9 +78,13 @@ export default createComponent({
methods: {
onScroll() {
const scrollTop = this.scroller === window
? getScrollTop(this.scroller)
: 0;
let scrollTop;
if (this.scroller === window || this.scroller === document.body) {
scrollTop = getScrollTop(this.scroller);
} else {
// see: https://github.com/youzan/vant/issues/3774
scrollTop = 0;
}
const rects = this.children.map(item => ({
height: item.height,
top: getElementTop(item.$el)
@@ -154,7 +159,7 @@ export default createComponent({
match[0].scrollIntoView();
if (this.stickyOffsetTop) {
window.scrollTo(0, getRootScrollTop() - this.stickyOffsetTop);
setRootScrollTop(getRootScrollTop() - this.stickyOffsetTop);
}
this.$emit('select', match[0].index);