swiper插入视频原生按钮失效
原因应该是swiper样式禁用了item里面的某些样式
关键样式 __pointer-events: none;改为__pointer-events: auto;
并通过视频事件做到滑动视频时,swiper停止视频播放的效果。
下面展示一些 内联代码片
。
html部分
<view class="bannerBox">
<swiper style="height: 300rpx;" class="swiper" @change="cardSwiper" circular="true"
indicator-dots="true" :autoplay="autoplay" interval="4000" duration="600">
<swiper-item class="swiper-list" v-for="(item, index) in bannerList" :key="index">
<view class="swiper-item uni-bg-red">
<image class="swiper-img radius shadow-warp"
v-if="item.adImg.indexOf('gif') != -1 || item.adImg.indexOf('jpg') != -1 || item.adImg.indexOf('png') != -1 || item.adImg.indexOf('jpeg') != -1"
:src="item.adImg" mode="widthFix">
</image>
<video :id="'myVideo'+index" controls="true" @play="playVideo()" @pause="pause" v-else
@ended="ended" page-gesture="true" object-fit="contain" show-mute-btn="true"
enable-play-gesture="true" :src="item.adImg"></video>
</view>
</swiper-item>
</swiper>
</view>
js部分
data() {
return {
videoContext: '',
autoplay: true, //自动切换轮播图
cardCur: 0,
bannerList: [],
}
},
methods: {
playVideo() {
console.log('play');
this.isShow = false
this.autoplay = false
},
// 视频暂停
pause() {
console.log('pause');
this.autoplay = true
},
// 视频结束
ended() {
console.log('ended');
this.autoplay = true
},
cardSwiper(e) {
this.cardCur = e.detail.current
let source = e.detail.source
if (source == 'touch') {
this.videoContext = uni.createVideoContext('myVideo' + (this.cardCur + this.bannerList.length - 1),
this)
this.videoContext.pause();
}
this.autoplay = true
},
getBanner() {
let opts = {
url: `/gh/adLists`
};
request.httpTokenRequest(opts).then(res => {
if (res.data.code == 200) {
// console.log(res.data.data);
this.bannerList = res.data.data
}
})
},
}
css部分
<style lang="scss" scoped>
.screen-swiper image,
.screen-swiper video,
.swiper-item image,
.swiper-item video {
pointer-events: auto !important;
}
.swiper-img {
height: 300rpx !important;
background-repeat: no-repeat;
background-size: contain;
background-position: center;
}
.swiper-item {
height: 100%;
}
</style>