微信小程序 scroll-view的使用案例代碼詳解
scroll-view
:滾動(dòng)視圖
使用view
其實(shí)也能實(shí)現(xiàn)滾動(dòng),跟div
用法差不多
而scroll-view
跟view
最大的區(qū)別就在于:scroll-view
視圖組件封裝了滾動(dòng)事件,監(jiān)聽滾動(dòng)事件什么的直接寫方法就行。
scroll-view
縱向滾動(dòng)添加屬性scroll-y
,然后寫一個(gè)固定高度就行了,我主要說一下scroll-view
的橫向滾動(dòng)scroll-x
:
我使用了display: flex;
布局,特么的直接寫在scroll-view上面,顯示出來的結(jié)果總是不對(duì)頭,試了好多次,得到了下面兩種寫法;
第二種在scroll-view上添加了enable-flex
啟用flex布局屬性,啟用后內(nèi)部就能使用flex布局了,不然你會(huì)發(fā)現(xiàn)內(nèi)部布局始終是縱向的。
得到的效果是一樣的,能使用scroll-view事件。
wxml:
<view class="order_item_body"> <scroll-view scroll-x="true" scroll-into-view="{{toView}}" scroll-left="{{scrollLeft}}"> <view class="order_item_list"> <view class="order_item_goods" wx:for="{{order.detail}}" wx:key="index" id="detail{{index}}"> <image src="{{item.image}}" mode="widthFix"></image> <text>{{item.count+index}}</text> </view> </view> </scroll-view> </view>
或
<scroll-view scroll-x bindscroll="scroll" scroll-into-view="{{toView}}" scroll-left="{{scrollLeft}}" enable-flex="{{true}}"> <view class="order_item_list"> <view class="order_item_goods" wx:for="{{order.detail}}" wx:key="index" id="detail{{index}}"> <image src="{{item.image}}" mode="widthFix"></image> <text>{{item.count+index}}</text> </view> </view> </scroll-view>
wxss:
.order_item_body{ width: 100%; height: 196rpx; } .order_item_list{ /* width: 100%; */ height: 100%; display: flex; flex-direction: row; justify-content: flex-start; align-items: center; /* border: 1px solid blue; */ } .order_item_goods { width: 200rpx; height: 192rpx; position: relative; } .order_item_goods>image { width: 160rpx; height: 160rpx; margin: 16rpx 20rpx; border: 1px solid rgba(0, 0, 0, 0.5); } .order_item_goods>text { height: 30rpx; line-height: 30rpx; padding: 0rpx 5rpx; font-size: 24rpx; color: rgba(255, 255, 255); border-top-left-radius: 10rpx; background-color: rgba(0, 0, 0, 0.5); position: absolute; bottom: 16rpx; right: 20rpx; }
效果圖:
求推薦一款免費(fèi)且沒有水印的gif制作軟件,有水印看到就煩。
ps:下面看下微信小程序scroll-view的scroll-into-view無效如何解決
最近在寫小程序項(xiàng)目遇到這么一個(gè)問題:在使用scroll-into-view的時(shí)候無效。
在網(wǎng)上查了一遍,給出的答案有:
1.給scroll-view要設(shè)置高度,必須設(shè)置上scroll-y或者scroll-x為true(必須要的)
2.scroll-into-view初始化設(shè)置的時(shí)候,可能因?yàn)轫撁婊蛘邤?shù)據(jù)未加載不能跳轉(zhuǎn)。需要在js里手動(dòng)setData一下。
一頓操作猛如虎,一看還是沒有效果。還是接著找原因吧。。
最后發(fā)現(xiàn),原來是在給scroll-view設(shè)置高度的時(shí)候,不能用%來設(shè)置高度,改成固定高度類似500rpx就可以了
最后貼上代碼:
<view class="left" wx:for="{{cateItems}}" wx:key="{{cateItems}}"> <view class='title' bindtap="navItem">{{item.name}}</view> </block> <scroll-view class="right" scroll-y="true" scroll-into-view="{{ intoindex }}" style="height: 1100rpx;" scroll-with-animation> <view class="clearfix" wx:for="{{cateItems}}" id="intoindex{{item.id}}"></view> </scroll-view> Page({ data: { intoindex:'' }, navItem(e){ const that = this var id = e.target.id that.setData({ intoindex:'intoindex'+id }) } })
總結(jié)
到此這篇關(guān)于微信小程序 scroll-view的使用案例代碼詳解的文章就介紹到這了,更多相關(guān)微信小程序 scroll-view的使用 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 詳解微信小程序scroll-view橫向滾動(dòng)的實(shí)踐踩坑及隱藏其滾動(dòng)條的實(shí)現(xiàn)
- 微信小程序使用scroll-view標(biāo)簽實(shí)現(xiàn)自動(dòng)滑動(dòng)到底部功能的實(shí)例代碼
- 微信小程序scroll-view實(shí)現(xiàn)滾動(dòng)穿透和阻止?jié)L動(dòng)的方法
- 微信小程序scroll-view仿拼多多橫向滑動(dòng)滾動(dòng)條
- 微信小程序scroll-view實(shí)現(xiàn)字幕滾動(dòng)
- 微信小程序scroll-view組件實(shí)現(xiàn)滾動(dòng)動(dòng)畫
相關(guān)文章
npm install 、npm install --save 和&n
這篇文章主要介紹了npm install 、npm install --save 和 npm install --save-dev的區(qū)別介紹,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04JS組件Bootstrap Table使用實(shí)例分享
這篇文章主要為大家詳細(xì)介紹了JS組件Bootstrap Table分頁使用方法,具有一定的實(shí)用性,感興趣的小伙伴們可以參考一下2016-05-05Javascript模塊化機(jī)制實(shí)現(xiàn)原理詳解
這篇文章主要介紹了Javascript模塊化機(jī)制實(shí)現(xiàn)原理詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04Raphael帶文本標(biāo)簽可拖動(dòng)的圖形實(shí)現(xiàn)代碼
Javascript和Raphael順便學(xué)習(xí)了一下,主要是為了實(shí)現(xiàn)一個(gè)可拖動(dòng)的矩形同時(shí)矩形上還得顯示標(biāo)簽,網(wǎng)上關(guān)于這方面的知識(shí)提的很是于是本人自不量力寫了一下,感興趣的你可不要錯(cuò)過了哈,希望可以幫助到你2013-02-02一個(gè)頁面元素appendchild追加到另一個(gè)頁面元素的問題
一般都是自己創(chuàng)建元素然后append到頁面的但是如果是頁面本身有的元素append到另一個(gè)頁面元素呢,很多的新手朋友對(duì)此問題比較好奇,本人也是如此啊,好了不多說,切入主題,感興趣的朋友可以了解下哦2013-01-01