在微信小程序中,使用 scroll-view 实现长页面的锚点跳转。主要是使用 scroll-into-view属性, 在这里做个记录。
wxml
<view class="tab-section" >
<view class="{
{activeView =='productBox' ? 'active':''}}" bindtap="toViewClick" data-toview="productBox">商品</view>
<view class="{
{activeView =='infoBox' ? 'active':''}}" bindtap="toViewClick" data-toview="infoBox">详情</view>
<view class="{
{activeView =='commentBox' ? 'active':''}}" bindtap="toViewClick" data-toview="commentBox">评价</view>
</view>
<scroll-view class="good-wrap"
style="height:{
{winHeight}}"
scroll-into-view="{
{toView}}"
scroll-y="true"
scroll-with-animation="true"
bindscroll="pageScroll">
<!-- 商品 -->
<view id="productBox" class="content img-section">
商品内容
</view>
<!-- 详情 -->
<view id="infoBox" class="content detail-section">
详情内容
</view>
<!-- 评价 -->
<view id="commentBox" class="content evaluate-section">
评价内容
</view