export const scrollToWithId = (
anchorId,
targetId,
proxy,
) => {
uni
.createSelectorQuery()
.select(anchorId)
.boundingClientRect((anchor) => {
uni
.createSelectorQuery()
// #ifdef MP-WEIXIN
.in(proxy)
// #endif
.select(targetId)
.boundingClientRect((rect) => {
const newAnchor = anchor as UniApp.NodeInfo;
const newRect = rect as UniApp.NodeInfo;
uni.pageScrollTo({
scrollTop: Math.abs((newRect?.top ?? 0) - (newAnchor?.top ?? 0)),
duration: 300,
});
})
.exec();
})
.exec();
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27