微信小程序?qū)崿F(xiàn)抖音播放效果的實例代碼
最近項目要做一個類似于抖音的一個視頻播放 需要小程序完成

在再次確定了需要這個需求的情況下就開始了(其實因為不是說這個功能不好做主要是但心做出來肯定不流暢 卡頓什么的 優(yōu)化不好優(yōu)化)
然后就開始啦
思路使用微信的 swiper 完成豎向滑動 然后分頁加載首先先加載一次加載10個當滑動到第7個的時候加載下一頁 (要處理自動播放的問題和加載多個有多個同時播放的問題)
效果圖

代碼
<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
},
//動態(tài)更新當前滑塊下標
bindchange(e) {
this.setData({
hkindex: e.detail.current
})
if (e.detail.current%10 == 7) {
this.chaxunzhi(); //此處是表示在快要加載完了需在分頁請求加載
}
},
//css代碼可能有多余的 我就不挑了 引入時自己按需引入吧
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;
}
完了需要注意的就是一個分頁加載 我設置的是7因為我們數(shù)據(jù)是一頁10條 會在第7條加載第二頁數(shù)據(jù)
wx:if="{{index==hkindex}}" 這個起到的是控制加載要不會多個同時播放沒刷到的也會播放 現(xiàn)在只會播放當前頁面視頻
總結(jié)
到此這篇關(guān)于微信小程序?qū)崿F(xiàn)抖音播放效果的實例代碼的文章就介紹到這了,更多相關(guān)微信小程序抖音播放內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
小程序websocket心跳庫(websocket-heartbeat-miniprogram)
這篇文章主要介紹了小程序websocket心跳庫(websocket-heartbeat-miniprogram),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-02-02
Bootstrap實現(xiàn)基于carousel.js框架的輪播圖效果
這篇文章主要為大家詳細介紹了Bootstrap實現(xiàn)基于carousel.js框架的輪播圖效果,無過渡動畫,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05
js實現(xiàn)權(quán)限樹的更新權(quán)限時的全選全消功能
上一篇發(fā)了添加權(quán)限時的權(quán)限樹JS源碼,下面把更新時的也發(fā)給大家借鑒一下,因為更新時候牽扯到判斷已有權(quán)限等,所以,還要麻煩一些。2009-02-02
使用layui實現(xiàn)的左側(cè)菜單欄以及動態(tài)操作tab項方法
今天小編就為大家分享一篇使用layui實現(xiàn)的左側(cè)菜單欄以及動態(tài)操作tab項方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-09-09

