uniapp小程序轮播图swiper插入视频 video按钮失效

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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值