微信小程序中使用 wx.pageScrollTo({)};进行页面锚点定位,一定要将根目录设置为滑动的根据。
也就是 page 要设置样式为 overflow-y: auto;指定他的高度。
在其中,设置一个容器 home 设置id。
在添加一个内容容器 container 设置类名。
设置多个锚点,添加锚点类型 如: node0, node1, node2 等。
然后通过点击事件传递要跳转的锚点信息。
通过wx.createSelectorQuery().select(类名).boundingClientRect(res => {}),, 获取锚点中的数据。
在通过wx.createSelectorQuery().select(“#home”).boundingClientRect(res => {}), 获取设置的跟锚点home。
在这里不能直接获取跟元素 page ,只能获取当前组件的根元素,也就是home。
在通过wx.pageScrollTo({ selector: “.container”, scrollTop: 滑动的距离 });就可以滑动到锚点。
vue2+vant. uniapp 项目
<template>
<view class="data_center">
<van-tabs
class&#