mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 18:54:24 +00:00
fix(IndexBar): incorrect behavior inside popup (#7559)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createNamespace } from '../utils';
|
||||
import { ChildrenMixin } from '../mixins/relation';
|
||||
import { BORDER_BOTTOM } from '../utils/constant';
|
||||
import { getScrollTop, getRootScrollTop } from '../utils/dom/scroll';
|
||||
|
||||
const [createComponent, bem] = createNamespace('index-anchor');
|
||||
|
||||
@@ -15,6 +16,7 @@ export default createComponent({
|
||||
return {
|
||||
top: 0,
|
||||
left: null,
|
||||
rect: { top: 0, height: 0 },
|
||||
width: null,
|
||||
active: false,
|
||||
};
|
||||
@@ -39,20 +41,35 @@ export default createComponent({
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.height = this.$el.offsetHeight;
|
||||
const rect = this.$el.getBoundingClientRect();
|
||||
this.rect.height = rect.height;
|
||||
},
|
||||
|
||||
methods: {
|
||||
scrollIntoView() {
|
||||
this.$el.scrollIntoView();
|
||||
},
|
||||
|
||||
getRect(scroller, scrollerRect) {
|
||||
const el = this.$el;
|
||||
const elRect = el.getBoundingClientRect();
|
||||
this.rect.height = elRect.height;
|
||||
|
||||
if (scroller === window || scroller === document.body) {
|
||||
this.rect.top = elRect.top + getRootScrollTop();
|
||||
} else {
|
||||
this.rect.top = elRect.top + getScrollTop(scroller) - scrollerRect.top;
|
||||
}
|
||||
|
||||
return this.rect;
|
||||
},
|
||||
},
|
||||
|
||||
render() {
|
||||
const { sticky } = this;
|
||||
|
||||
return (
|
||||
<div style={{ height: sticky ? `${this.height}px` : null }}>
|
||||
<div style={{ height: sticky ? `${this.rect.height}px` : null }}>
|
||||
<div
|
||||
style={this.anchorStyle}
|
||||
class={[bem({ sticky }), { [BORDER_BOTTOM]: sticky }]}
|
||||
|
Reference in New Issue
Block a user