溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

微信小程序中scroll-view如何實(shí)現(xiàn)錨點(diǎn)跳轉(zhuǎn)功能

發(fā)布時(shí)間:2021-05-20 14:47:07 來源:億速云 閱讀:338 作者:小新 欄目:web開發(fā)

這篇文章將為大家詳細(xì)講解有關(guān)微信小程序中scroll-view如何實(shí)現(xiàn)錨點(diǎn)跳轉(zhuǎn)功能,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

在微信小程序中,使用 scroll-view 實(shí)現(xiàn)長頁面的標(biāo)記跳轉(zhuǎn),官方文檔中沒有例子演示,錨點(diǎn)標(biāo)記主要是使用<scroll-view> 的 scroll-into-view 屬性。

  實(shí)現(xiàn)錨點(diǎn)跳轉(zhuǎn)主要以下幾點(diǎn):

  1、最外層容器使用 scroll-view

  2、賦值scroll-into-view,如:<scroll-view scroll-into-view="{{toView}}">

  3、設(shè)置 scroll-view 滾動(dòng)方向 scroll-y="true"

  4、跳轉(zhuǎn)到的位置使用 id (定位),如:<view id="mark1">

<view class="list">
  <view bindtap=‘jumpTo‘ data-opt="list0">list0</view>
  <view bindtap=‘jumpTo‘ data-opt="list11">list11</view>
  <view bindtap=‘jumpTo‘ data-opt="list29">list29</view>
</view>
<scroll-view scroll-into-view="{{toView}}" scroll-y="true" scroll-with-animation="true">
  <view wx:for="{{list}}" id="{{item}}" class="test">
   {{item}}
  </view>
</scroll-view>

 data: {
  list: ["list0", "list1", "list2"],
  toView: ‘‘
 },
 jumpTo: function (e) {
  // 獲取標(biāo)簽元素上自定義的 data-opt 屬性的值
  let target = e.currentTarget.dataset.opt;
  this.setData({
   toView: target
  })
 },

關(guān)于“微信小程序中scroll-view如何實(shí)現(xiàn)錨點(diǎn)跳轉(zhuǎn)功能”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI