小程序點(diǎn)擊圖片實(shí)現(xiàn)自動(dòng)播放視頻
通過列表的點(diǎn)擊事件自動(dòng)播放列表對(duì)應(yīng)的視頻,同時(shí)停止上一個(gè)視頻的播放。
源碼:
<view> <view class='vv' wx:for='{{vedio_data}}' wx:key=''> <view class='block' style='margin-left:20rpx;'> <image src='/img/1.png' class='img1' style='margin-left:20rpx'></image> <text class='text'>{{item.title}} </text> <view id="{{index}}" class="cover" style="display: {{ _index == index ? 'none' : 'block' }};" bindtap="videoPlay" > <!-- 視頻圖層 --> <image class="videoVideo2" src="{{item.img}}" mode="scaleToFill"> <!-- 視頻按鈕 --> <image class="videoPlay" src="/img/bf.png" mode="scaleToFill"></image> </image> </view> </view> <!-- 視頻 --> <video src="{{item.url}}" id="{{index}}" class='video' wx:if="{{_index == index}}" > <!-- log --> </video> </view> <view class='di'> <image src='/img/qd.png' class='bottom'></image> <text class='bottom_text'>敬請(qǐng)期待</text> </view> </view>
CSS:
/* 邊框 */ .vv { width: 700rpx; height: 530rpx; border-left: gainsboro 1px solid; border-right: gainsboro 1px solid; border-top: gainsboro 1px solid; margin-bottom: 80rpx; border-radius: 15rpx; overflow: hidden; position: relative; top: 40rpx; left: 20rpx; } /* 小圖標(biāo) */ .img1 { width: 36rpx; height: 28rpx; margin-top: 30rpx; } /* 標(biāo)題文字 */ .text { font-size: 28rpx; color: #585858; margin-left: 10rpx; } /* 視頻 */ .video { width: 100%; height: 450rpx; margin-top: 20rpx; border-bottom-left-radius: 15rpx; border-bottom-right-radius: 15rpx; } .videoVideo2 { width: 703rpx; height: 453rpx; position: absolute; top: 80rpx; left: 20rpx; z-index: 99; } .videoPlay{ position: absolute; width: 80rpx; height: 80rpx; top:45%; left: 45%; margin: -30rpx 0 0 -30rpx; z-index: 100; } /* 底部盒子 */ .bottom { width: 40rpx; height: 40rpx; } /* 底部圖片 */ .di { display: flex; flex-direction: row; padding: 60rpx 0rpx 100rpx 280rpx; } /* 底部文字 */ .bottom_text { font-size: 34rpx; color: #d8d8d8; margin-left: 10rpx; }
JS:
// pages/class/class.js Page({ /** * 頁(yè)面的初始數(shù)據(jù) */ data: { videoPlay: null, vedio_data: [{ title: '無13131(大班)', url: 'xxx', img: 'xxx', }, { title: ' 如何23 1 、 2 、2423、4)', url: 'xxx', img: 'xxx' }, { title: '溫?zé)岬K', url: 'xxx', img:'xxx' }, { title: '挑嘎嘎嘎輸', url: 'xxx', img: 'xxx' }, { title: '延伸挑戰(zhàn):運(yùn)輸圓球', url: 'xxx', img:'xxx' }, ] }, // 點(diǎn)擊cover播放,其它視頻結(jié)束 videoPlay: function (e) { var _index = e.currentTarget.id this.setData({ _index: _index }) //停止正在播放的視頻 var videoContextPrev = wx.createVideoContext(this.data._index) videoContextPrev.stop(); setTimeout(function(){ //將點(diǎn)擊視頻進(jìn)行播放 var videoContext = wx.createVideoContext(_index) videoContext.play(); },500) }, })
視頻和圖片地址就不提供了。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
深入理解JavaScript字節(jié)二進(jìn)制知識(shí)以及相關(guān)API
當(dāng)前,前端對(duì)二進(jìn)制數(shù)據(jù)有許多的API可以使用,這豐富了前端對(duì)文件數(shù)據(jù)的處理能力,有了這些能力,就能夠?qū)D片等文件的數(shù)據(jù)進(jìn)行各種處理。本文將著重介紹一些前端二進(jìn)制數(shù)據(jù)處理相關(guān)的API知識(shí),希望對(duì)大家有所幫助2023-02-02JS 截取字符串substr 和 substring方法的區(qū)別
JS 截取字符串substr 和 substring方法的區(qū)別,需要的朋友可以參考下,根據(jù)需要自行選擇。2009-10-10詳解關(guān)于html,css,js三者的加載順序問題
這篇文章主要介紹了關(guān)于html,css,js三者的加載順序問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04使用window.prompt()實(shí)現(xiàn)彈出用戶輸入的對(duì)話框
window對(duì)象的最后一種對(duì)話框是提示對(duì)話框,它顯示了預(yù)先設(shè)置的信息并提供文本域供用戶輸入應(yīng)答。它包括兩個(gè)按鈕,即Cancel和Ok,允許用戶用兩個(gè)相反的期望值來關(guān)閉這個(gè)對(duì)話框:取消整個(gè)操作或接收輸入到對(duì)話框中的文本2015-04-04JavaScript使用sort函數(shù)實(shí)現(xiàn)漢字排序
JavaScript中的sort函數(shù)是一個(gè)強(qiáng)大且多用途的工具,能夠?qū)?shù)組的元素進(jìn)行排序,而漢字按照拼音排序又是一個(gè)常見需求,下面我們就來看看如何使用JavaScript實(shí)現(xiàn)漢字排序吧2023-12-12Javascript實(shí)現(xiàn)簡(jiǎn)單二級(jí)下拉菜單實(shí)例
這篇文章主要介紹Javascript實(shí)現(xiàn)二級(jí)下拉菜單的具體過程,需要的朋友可以參考下2014-06-06RGB顏色值轉(zhuǎn)HTML十六進(jìn)制(HEX)代碼的JS函數(shù)
轉(zhuǎn)到固定長(zhǎng)度的十六進(jìn)制字符串,不夠則補(bǔ)0 javascript找出一個(gè)背景色的數(shù)值,只好自己解析2009-04-04JavaScript判斷對(duì)象是否為空對(duì)象的幾種常見方法
經(jīng)典面試題,研發(fā)時(shí)也經(jīng)常遇見的一個(gè)問題,如何判斷一個(gè)對(duì)象是空對(duì)象,這篇文章主要給大家介紹了關(guān)于JavaScript判斷對(duì)象是否為空對(duì)象的幾種常見方法,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-06-06es6函數(shù)name屬性功能與用法實(shí)例分析
這篇文章主要介紹了es6函數(shù)name屬性,結(jié)合實(shí)例形式分析了es6函數(shù)name屬性基本原理、功能、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04JS動(dòng)態(tài)圖片的實(shí)現(xiàn)方法完整示例
這篇文章主要介紹了JS動(dòng)態(tài)圖片的實(shí)現(xiàn)方法,結(jié)合完整實(shí)例形式分析了JavaScript鼠標(biāo)響應(yīng)與頁(yè)面元素屬性動(dòng)態(tài)變換相關(guān)操作技巧,需要的朋友可以參考下2020-01-01