当前位置 主页 > 服务器问题 > Linux/apache问题 >
“锚点”功能在实际应用设计的好,可以提高用户体验。今天碰到一个类似下面功能:
由于页面数据比较多,除了做些上拉加载,下拉刷新等优化。还可以进行进行分类,如上图。功能要求:点击导航的菜单,相应页面的分类内容滑动到页面顶部。由于微信小程序页面无dom操作,改功能改如何操作呢?
一开始想到 wx.pageScrollTo(Object object) 这个API,由于每个点击每个导航利用wx.pageScrollTo滚动到相应分类的scrollTop不能确定,所以放弃了。
后发现 scroll-view 组件 的属性 scroll-into-view 可以利用一下:
<scroll-view scroll-y scroll-into-view="{{toView}}" bindscroll="scrollTopFun" scroll-top="{{scrollTop.scroll_top}}" scroll-with-animation="true" > <!-- 内容 --> <view class='bg-white m-t10'> <view class='flex'> <view class='flex-1 f16 p-v text-center {{currentId === index? "active":""}}' data- bindtap='navHandleClick' wx:for="{{navietm}}" wx:key="{{index}}">{{item}}</view> </view> <view class='has-padding-sm'> <!-- 实时停电信息 --> <view> <view class='m-t10' wx:for="{{navlist}}" wx:key="{{index}}"> <view class='itembox' id='{{item.id}}'> <view class='titlebox flex'> <view class='flex-1 text-ellipsis'>{{item.name}}</view> <view class='f12'> <text class='icon icon-like-o inline-middle'></text> <text class='inline-middle m-l5'>加入关注</text> </view> </view> <view class='itemconbox'> <view class='flex c9'> <view class='line m-r5 flex-1 self-middle'></view> ·<text class='p-w-sm'>昨天</text>· <view class='line m-l5 flex-1 self-middle'></view> </view> <view class='bg-white p-w-sm radius-sm m-t5' bindtap="togglePopup"> <view class='border-line-b flex text-bold p-t5 p-b5'> <view class='flex-1'> <image src='../../images/date.png' class='ico-date inline-middle'></image> <text class='inline-middle m-l10'>2018-09-12 22:15:00</text> </view> <view>电网故障停限电</view> </view> <view class='p-w-sm p-v-sm'> <view> <text class='text-bold m-r10 c-11A99A'>送电时间:</text> <text class='f12 c6'>2018-09-13 16:15:00</text> <text class='label bg-A5A5A5'>预计</text> </view> <view> <text class='text-bold m-r10 c-11A99A'>停电范围:</text> <text class='f12 c6'>[开福区] 湘江世纪城、湘江世纪城、湘江世纪城、湘江世纪城、湘江世纪城、湘江世纪城、</text> </view> <view> <text class='text-bold m-r10 c-11A99A'>停电区域:</text> <text class='f12 c6'>湖南省长沙市开福区</text> </view> </view> </view> </view> <view class='itemconbox'> <view class='flex c9'> <view class='line m-r5 flex-1 self-middle'></view> ·<text class='p-w-sm'>昨天</text>· <view class='line m-l5 flex-1 self-middle'></view> </view> <view class='bg-white p-w-sm radius-sm m-t5' bindtap="togglePopup"> <view class='border-line-b flex text-bold p-t5 p-b5'> <view class='flex-1'> <image src='../../images/date.png' class='ico-date inline-middle'></image> <text class='inline-middle m-l10'>2018-09-12 22:15:00</text> </view> <view>电网故障停限电</view> </view> <view class='p-w-sm p-v-sm'> <view> <text class='text-bold m-r10 c-11A99A'>送电时间:</text> <text class='f12 c6'>2018-09-13 16:15:00</text> <text class='label bg-A5A5A5'>预计</text> </view> <view> <text class='text-bold m-r10 c-11A99A'>停电范围:</text> <text class='f12 c6'>[开福区] 湘江世纪城、湘江世纪城、湘江世纪城、湘江世纪城、湘江世纪城、湘江世纪城、</text> </view> <view> <text class='text-bold m-r10 c-11A99A'>停电区域:</text> <text class='f12 c6'>湖南省长沙市开福区</text> </view> </view> </view> </view> </view> </view> <view class='text-center p-t10 f12 c9'> 没有更多信息了 </view> </view> </view> </view> </scroll-view> <!-- 导航 --> <view class='nav-fixed' wx:if="{{scrollTop.goTop_show}}"> <!-- 滚动到离顶部一定距离在显示导航按钮 --> <view class='navitembtn shadow {{isnavfixed ? "":"navitembtned"}}' catchtap='navfixedHandleClick'>导航</view> <view class='navconbox' hidden='{{isnavfixed}}'> <view class='floor gotop' catchtap='gotop'>返回顶部</view> <view class='floor' bindtap='clickScroll' data- wx:for="{{navlist}}" wx:key="{{index}}"> {{item.name}} </view> </view> </view>