微信小程序停止其他視頻播放當前視頻的實例代碼
更新時間:2019年12月25日 09:08:47 作者:ssorth
這篇文章主要介紹了微信小程序停止其他視頻播放當前視頻的實例代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
微信小程序停止其他視頻播放當前視頻,代碼如下所示:
<view class="content"> <!--首頁--> <scroll-view class='nav-page'> <view class="item-box " wx:for="{{videelsi}}" wx:key="item"> <!-- 標題層 --> <!-- 視頻圖片層 --> <view data-id="{{index}}" class="video-image-box" style="display: {{ _index == index ? 'none' : 'block' }};" bindtap="videoPlay"> <view class="video-cover-box"> <image class="video-image" src="{{item.cover}}" mode="aspectFit"> </image> </view> <!-- 視頻按鈕 --> <image class="video-image-play" src="../image/vidoe.png" mode="scaleToFill"></image> </view> <!-- 視頻播放層 --> <video enable-progress-gesture show-play-btn src="{{item.src}}" data-id="{{index}}" class='video' wx:if="{{_index == index}}" objectFit='contain' autoplay='true' controls></video> <cover-view style="display: {{ _index == index ? 'none' : 'block' }};" class="video-title-box"> <cover-view class='video-title'>{{item.title}}</cover-view> </cover-view> </view> </scroll-view> </view>`
css 樣式
.content { border-top: transparent 1px solid; box-sizing: border-box; /* height: 100%; */ width: 100%; padding: 0 20rpx; } .container{ border-top: transparent 1px solid; /* box-sizing: border-box; */ /* height: 100%; */ width: 100%; } view { vertical-align:middle; } .item-box { width: 100%; margin-top: 40rpx; position: relative; } .video-title-box{ height: 70rpx; width: 100%; background:rgba(0,0,0,1); opacity:0.2; position: absolute; bottom: 10rpx; } .video-title{ text-align: center; font-size: 30rpx; line-height: 70rpx; font-weight:400; color:rgba(255,255,255,1); } .item-box{ width: 100%; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp:2; overflow: hidden; text-overflow:ellipsis; } .item-box .video-image-box { height: 400rpx; width: 100%; background-repeat: no-repeat; background-size: 100% 100%; background-position-x: 30rpx; position: relative; } .video-cover-box{ height: 100%; width: 100%; text-align: center; line-height: 0rpx; } .item-box:first-of-type{ margin-top: 0rpx; } .item-box .video-image-box .video-cover-box .video-image { height: 100%; width: 100%; } .item-box .video { height: 300rpx; width: 100%; margin: 0 30rpx 0 0; position: relative; } .item-box .video-image-box .video-image-play { position: absolute; width: 80rpx; height: 80rpx; top: calc(50% - 40rpx); left: calc(50% - 40rpx); z-index: 100; }
js 代碼
const app = getApp() Page({ data: { videoPlay: null, videelsi: [], }, onLoad: function () { wx.hideShareMenu() this.vidoelist() }, vidoelist() { app.api.getData(app.data.https + 'wechat/farm/index').then(res => { console.log(res) this.setData({ videelsi: res.data.list }) }) }, // 點擊cover播放,其它視頻結(jié)束 videoPlay: function (e) { var _index = e.currentTarget.dataset.id this.setData({ _index: _index }) //停止正在播放的視頻 var videoContextPrev = wx.createVideoContext(_index + "") videoContextPrev.stop(); setTimeout(function () { //將點擊視頻進行播放 var videoContext = wx.createVideoContext(_index + "") videoContext.play(); }, 500) } })
總結(jié)
以上所述是小編給大家介紹的微信小程序停止其他視頻播放當前視頻,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
深入理解javascript動態(tài)插入技術(shù)
這篇文章介紹了javascript動態(tài)插入技術(shù),有需要的朋友可以參考一下2013-11-11JS構(gòu)造一個html文本內(nèi)容成文件流形式發(fā)送到后臺
本文通過實例代碼給大家介紹了JS構(gòu)造一個html文本內(nèi)容成文件流形式發(fā)送到后臺的相關(guān)資料,需要的朋友可以參考下2018-07-07使用Three.js實現(xiàn)太陽系八大行星的自轉(zhuǎn)公轉(zhuǎn)示例代碼
這篇文章主要給大家介紹了關(guān)于如何使用Three.js實現(xiàn)太陽系八大行星的自轉(zhuǎn)公轉(zhuǎn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Three.js具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-04-04LayUI+Shiro實現(xiàn)動態(tài)菜單并記住菜單收展的示例
這篇文章主要介紹了LayUI+Shiro實現(xiàn)動態(tài)菜單并記住菜單收展的示例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2021-05-05JavaScript/jQuery 表單美化插件小結(jié)
用過一些表單美化的工具,覺得不錯,特地分享一下2012-02-02