wxml:css
<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}}" >
</video>
</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;
}
/* 小圖標 */
.img1 {
width: 36rpx;
height: 28rpx;
margin-top: 30rpx;
}
/* 標題文字 */
.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;
}
js:
data: {
videoPlay: null,
vedio_data: [{
title: '循環的標題1',
url: '視頻路徑',
img: '圖片路徑',
},
{
vedio_data: [{
title: '循環的標題2',
url: '視頻路徑',
img: '圖片路徑',
},
{
vedio_data: [{
title: '循環的標題3',
url: '視頻路徑',
img: '圖片路徑',
}
]
},
// 點擊cover播放,其它視頻結束
videoPlay: function (e) {
var _index = e.currentTarget.id
this.setData({
_index: _index
})
//中止正在播放的視頻
var videoContextPrev = wx.createVideoContext(this.data._index)
videoContextPrev.stop();
setTimeout(function(){
//將點擊視頻進行播放
var videoContext = wx.createVideoContext(_index)
videoContext.play();
},500)
},
若有其餘問題能夠加qq羣:581478349 把問題直接發羣裏會有人叫你怎麼解決