微信小程序?qū)崿F(xiàn)抖音播放效果的實(shí)例代碼
最近項(xiàng)目要做一個(gè)類似于抖音的一個(gè)視頻播放 需要小程序完成
在再次確定了需要這個(gè)需求的情況下就開始了(其實(shí)因?yàn)椴皇钦f這個(gè)功能不好做主要是但心做出來肯定不流暢 卡頓什么的 優(yōu)化不好優(yōu)化)
然后就開始啦
思路使用微信的 swiper 完成豎向滑動(dòng) 然后分頁加載首先先加載一次加載10個(gè)當(dāng)滑動(dòng)到第7個(gè)的時(shí)候加載下一頁 (要處理自動(dòng)播放的問題和加載多個(gè)有多個(gè)同時(shí)播放的問題)
效果圖
代碼
<swiper class="swiper" vertical='true' easing-function='default' bindchange='bindchange'> <block wx:for="{{weishipinglist}}" wx:for-item="key" wx:key="*this"> <swiper-item> <view class="video-wrap"> <video wx:if="{{index==hkindex}}" class="video" autoplay="{{true}}" lopp='{{true}}' src="{{key.videoid}}" enable-play-gesture='{{true}}' show-fullscreen-btn='{{false}}' controls='{{false}}' vslide-gesture-in-fullscreen='{{false}}' show-play-btn='{{false}}' enable-progress-gesture='{{false}}' show-mute-btn='{{false}}'></video> <button class="buy" bindtap="click">{{index}}</button> </view> </swiper-item> </block> </swiper>
data: { weishipinglist: [],//視頻數(shù)據(jù) hkindex: 0,//滑塊index }, //動(dòng)態(tài)更新當(dāng)前滑塊下標(biāo) bindchange(e) { this.setData({ hkindex: e.detail.current }) if (e.detail.current%10 == 7) { this.chaxunzhi(); //此處是表示在快要加載完了需在分頁請(qǐng)求加載 } },
//css代碼可能有多余的 我就不挑了 引入時(shí)自己按需引入吧 page { width: 100%; height: 100%; } .video-wrap { width: 100%; height: 100%; position: relative; /* border: 1px dashed red; */ } .video-wrap video { width: 100%; height: 100%; position: absolute; top: 0px; left: 0; z-index: 1; } .video-wrap .buy { width: 100rpx; height: 100rpx; line-height: 100rpx; border-radius: 50%; position: absolute; z-index: 100; bottom: 100rpx; left: 50rpx; font-size: 11pt; text-align: center; padding: 0px; } .swiper { width: 100%; height: 100%; } .tentbiaot { width: 400rpx; font-size: 30rpx; color: #fff; z-index: 99; white-space: normal; line-height: 40rpx; margin-top: 20rpx; } .diwen { width: 400rpx; color: #fff; z-index: 99; display: flex; align-items: center; } .toixaign { width: 50rpx; height: 50rpx; border-radius: 50rpx; margin-right: 10rpx; } .teiename { font-size: 34rpx; margin-right: 10rpx; } .diwe { display: flex; position: fixed; bottom: 100rpx; flex-direction: column; z-index: 99; left: 40rpx; } .dianzaidijila { width: 100rpx; position: fixed; right: 30rpx; bottom: 80rpx; display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 99; } .tuaobiao { display: flex; align-items: center; flex-direction: column; justify-content: center; margin-bottom: 30rpx; } .tobimg{ width: 60rpx; height: 50rpx; } .tobimglw{ width: 60rpx; height: 60rpx; margin-bottom: 20rpx; } .zitiet{ color: #fff; font-size: 26rpx; margin-top: 6rpx; } .zhaunfanan { width: 60rpx; height: 50rpx; padding: 0rpx; border: none !important; line-height: 0rpx; } .zhaunfananas { width: 60rpx; height: 50rpx; }
完了需要注意的就是一個(gè)分頁加載 我設(shè)置的是7因?yàn)槲覀償?shù)據(jù)是一頁10條 會(huì)在第7條加載第二頁數(shù)據(jù)
wx:if="{{index==hkindex}}" 這個(gè)起到的是控制加載要不會(huì)多個(gè)同時(shí)播放沒刷到的也會(huì)播放 現(xiàn)在只會(huì)播放當(dāng)前頁面視頻
總結(jié)
到此這篇關(guān)于微信小程序?qū)崿F(xiàn)抖音播放效果的實(shí)例代碼的文章就介紹到這了,更多相關(guān)微信小程序抖音播放內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
js彈性勢(shì)能動(dòng)畫之拋物線運(yùn)動(dòng)實(shí)例詳解
這篇文章主要為大家詳細(xì)介紹了js彈性勢(shì)能動(dòng)畫之拋物線運(yùn)動(dòng)的制作方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07javascript設(shè)計(jì)模式 – 組合模式原理與應(yīng)用實(shí)例分析
這篇文章主要介紹了javascript設(shè)計(jì)模式 – 組合模式,結(jié)合實(shí)例形式分析了javascript組合模式相關(guān)概念、原理、應(yīng)用場(chǎng)景及相關(guān)使用注意事項(xiàng),需要的朋友可以參考下2020-04-04JS禁用頁面上所有控件的實(shí)現(xiàn)方法(附demo源碼下載)
這篇文章主要介紹了JS禁用頁面上所有控件的方法,涉及JavaScript捕捉頁面元素的相關(guān)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2015-12-12JavaScript利用split函數(shù)按規(guī)定截取字符串(獲取郵箱用戶名)
這個(gè)其實(shí)就是利用了js的split函數(shù),以@分割數(shù)組,一般用這個(gè)的地方不多,但這個(gè)思路應(yīng)用的比較廣泛。推薦大家學(xué)習(xí)。2009-12-12微信小程序如何實(shí)現(xiàn)radio單選框單擊打勾和取消
這篇文章主要介紹了微信小程序如何實(shí)現(xiàn)radio單選框單擊打勾和取消,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01