uni-app 滾動到指定位置的操作方法
方法1:使用標簽,可以將頁面橫向(或縱向)滾動到指定位置
無法滾動 將代碼放在setTimeout,nextTick里執(zhí)行
<!-- 左邊 --> <scroll-view show-scrollbar="false" scroll-y="true" class="left-box" :scroll-top="scrollLeftTop" scroll-with-animation="true"> <view class="scroll-view-item" v-for="(item,index) in servicesLeftList" :key="item.id" :id="'scroll' + activeLeftTab" :class="{'active':activeLeftTab==item.id}"> {{item.name}} </view> </scroll-view>
data(){ return { servicesLeftList:[], scrollLeftTop:0,,//滾動位置 activeLeftTab:"" //選中的樣式 } } getData() { //接口 getServicesTree().then(res => { this.servicesLeftList= res.data res.data.forEach((item, ind) => { setTimeout(()=>{ uni.createSelectorQuery().in(this).select('#scroll' + item.id) .boundingClientRect(res => { scrollLeftTop.value = 65 * ind; // 設置滾動條距離左側的距離 }).exec() },100) }) }) }
方法二 使用uni.pageScrollTo 使頁面縱向滾到到指定位置
建議設置height為auto :height:auto
<view class="left-box" > <view class="scroll-view-item" v-for="(item,index) in servicesLeftList" :key="item.id" :class="{'active':activeLeftTab==item.id}"> {{item.name}} </view> </view> //方法 uni.pageScrollTo({ scrollTop: 0, duration: 500 });
方法三 用scroll-view描點
//左邊 :scroll-top="scrollLeftTop" <scroll-view scroll-y="true" class="left-box" scroll-with-animation="true" :scroll-into-view="tracingLeftPoint"> <view class="scroll-view-item" v-for="(item,index) in servicesLeftList" :key="item.id" :id="'scroll' + item.id" :class="{'active':activeLeftTab==item.id}"> {{item.name}} </view> </scroll-view> //方法 data(){ retrun { tracingLeftPoint:"",//描點id } } getData() { //接口 getServicesTree().then(res => { this.servicesLeftList= res.data res.data.forEach((item, ind) => { setTimeout(()=>{ this.tracingLeftPoint= 'scroll' + item.id },200) }) }) }
到此這篇關于uni-app 滾動到指定位置的文章就介紹到這了,更多相關uni-app 滾動到指定位置內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
javascript Array數(shù)組對象的擴展函數(shù)代碼
我們經(jīng)常給 String,Function,Array 的原型加上自定義的擴展函數(shù),比如去除字符串空格,數(shù)組排序等2010-05-05PHP+jQuery+Ajax+Mysql如何實現(xiàn)發(fā)表心情功能
這篇文章通過php+jquery+ajax+mysql相結合,實現(xiàn)當用戶瀏覽網(wǎng)站文章或者是論壇帖子后,想表達自己瀏覽后的心情,發(fā)表自己的感受,很多網(wǎng)站都提供了用戶發(fā)表心情的功能,通過此功能可以很直觀的分析文章或者是論壇對瀏覽者的用戶體驗度2015-08-08JS響應鼠標點擊實現(xiàn)兩個滑塊區(qū)間拖動效果
這篇文章主要介紹了JS實現(xiàn)的兩個滑塊區(qū)間拖動效果代碼,涉及JavaScript響應鼠標事件針對頁面元素的動態(tài)操作技巧,需要的朋友可以參考下2015-10-10js使用棧來實現(xiàn)10進制轉(zhuǎn)8進制與取除數(shù)及余數(shù)
這篇文章主要介紹了js使用棧來實現(xiàn)10進制轉(zhuǎn)8進制、js取除數(shù)、余數(shù),需要的朋友可以參考下2014-06-06JS+flash實現(xiàn)chrome和ie瀏覽器下同時可以復制粘貼
chrome和ie同時可以復制粘貼,想必大家一直思索的問題在本文將有一個不錯的實現(xiàn),下面為大家介紹下JS+flash是如何實現(xiàn)的,感興趣的朋友可以參考下2013-09-09