mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-08-29 20:29:46 +08:00
parent
a44b3b4ed9
commit
36bf4762eb
@ -87,8 +87,10 @@ VantComponent({
|
|||||||
|
|
||||||
setAnchorsRect() {
|
setAnchorsRect() {
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
this.children.map(anchor => (
|
this.children.map(anchor =>
|
||||||
anchor.getRect('.van-index-anchor-wrapper').then(
|
anchor
|
||||||
|
.getRect('.van-index-anchor-wrapper')
|
||||||
|
.then(
|
||||||
(rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
|
(rect: WechatMiniprogram.BoundingClientRectCallbackResult) => {
|
||||||
Object.assign(anchor, {
|
Object.assign(anchor, {
|
||||||
height: rect.height,
|
height: rect.height,
|
||||||
@ -96,7 +98,7 @@ VantComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
))
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -135,23 +137,17 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getAnchorRect(anchor) {
|
getAnchorRect(anchor) {
|
||||||
return anchor.getRect('.van-index-anchor-wrapper').then(
|
return anchor
|
||||||
(rect: WechatMiniprogram.BoundingClientRectCallbackResult) => (
|
.getRect('.van-index-anchor-wrapper')
|
||||||
{
|
.then((rect: WechatMiniprogram.BoundingClientRectCallbackResult) => ({
|
||||||
height: rect.height,
|
height: rect.height,
|
||||||
top: rect.top
|
top: rect.top
|
||||||
}
|
}));
|
||||||
)
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getActiveAnchorIndex() {
|
getActiveAnchorIndex() {
|
||||||
const { children } = this;
|
const { children } = this;
|
||||||
const {
|
const { sticky, scrollTop, stickyOffsetTop } = this.data;
|
||||||
sticky,
|
|
||||||
scrollTop,
|
|
||||||
stickyOffsetTop
|
|
||||||
} = this.data;
|
|
||||||
|
|
||||||
for (let i = this.children.length - 1; i >= 0; i--) {
|
for (let i = this.children.length - 1; i >= 0; i--) {
|
||||||
const preAnchorHeight = i > 0 ? children[i - 1].height : 0;
|
const preAnchorHeight = i > 0 ? children[i - 1].height : 0;
|
||||||
@ -166,9 +162,7 @@ VantComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
onScroll() {
|
onScroll() {
|
||||||
const {
|
const { children = [] } = this;
|
||||||
children = []
|
|
||||||
} = this;
|
|
||||||
|
|
||||||
if (!children.length) {
|
if (!children.length) {
|
||||||
return;
|
return;
|
||||||
@ -195,7 +189,8 @@ VantComponent({
|
|||||||
let isActiveAnchorSticky = false;
|
let isActiveAnchorSticky = false;
|
||||||
|
|
||||||
if (active !== -1) {
|
if (active !== -1) {
|
||||||
isActiveAnchorSticky = children[active].top <= stickyOffsetTop + scrollTop;
|
isActiveAnchorSticky =
|
||||||
|
children[active].top <= stickyOffsetTop + scrollTop;
|
||||||
}
|
}
|
||||||
|
|
||||||
children.forEach((item, index) => {
|
children.forEach((item, index) => {
|
||||||
@ -230,7 +225,8 @@ VantComponent({
|
|||||||
const currentAnchor = children[index];
|
const currentAnchor = children[index];
|
||||||
|
|
||||||
const currentOffsetTop = currentAnchor.top;
|
const currentOffsetTop = currentAnchor.top;
|
||||||
const targetOffsetTop = index === children.length - 1
|
const targetOffsetTop =
|
||||||
|
index === children.length - 1
|
||||||
? this.top
|
? this.top
|
||||||
: children[index + 1].top;
|
: children[index + 1].top;
|
||||||
|
|
||||||
@ -257,7 +253,7 @@ VantComponent({
|
|||||||
data: {
|
data: {
|
||||||
active: false,
|
active: false,
|
||||||
anchorStyle: '',
|
anchorStyle: '',
|
||||||
wrapperStyle: '',
|
wrapperStyle: ''
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -295,14 +291,18 @@ VantComponent({
|
|||||||
|
|
||||||
this.scrollToAnchorIndex = index;
|
this.scrollToAnchorIndex = index;
|
||||||
|
|
||||||
const anchor = this.children.filter(item => item.data.index === this.data.indexList[index])[0];
|
const anchor = this.children.find(
|
||||||
|
(item: WechatMiniprogram.Component.TrivialInstance) =>
|
||||||
|
item.data.index === this.data.indexList[index]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (anchor) {
|
||||||
this.$emit('select', anchor.data.index);
|
this.$emit('select', anchor.data.index);
|
||||||
|
wx.pageScrollTo({
|
||||||
anchor && wx.pageScrollTo({
|
|
||||||
duration: 0,
|
duration: 0,
|
||||||
scrollTop: anchor.top
|
scrollTop: anchor.top
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user