当前位置: 首页 > article >正文

创意实现!在uni-app小程序商品详情页轮播中嵌入视频播放功能

背景介绍

通过uni-app框架实现商城小程序商品详情页的视频与图片轮播功能,以提升用户体验和增加商品吸引力。通过展示商品视频和图片,用户可以更全面地了解商品细节,从而提高购买决策的便利性和满意度。这种功能适用于各类商品,如服装、家具、电子产品等。通过本文的步骤,您将学会如何在商城小程序中利用uni-app框架实现商品详情页的视频与图片轮播功能。

代码组件

新建文件:productConSwiper.vue

<template>
	<view class='product-bg'>
		<swiper :indicator-dots="indicatorDots" indicator-active-color="#E93323" :autoplay="autoplay"
			:circular="circular" :interval="interval" :duration="duration" @change="change">

			<swiper-item v-if="videoline">
				<view class="item">
					<view v-if="!controls" style="width:100%;height:100% ">
						<video id="myVideo" :src='videoline' objectFit="cover" controls style="width:100%;height:100% "
							show-center-play-btn show-mute-btn="true" auto-pause-if-navigate :custom-cache="false"
							:enable-progress-gesture="false" :poster="imgUrls[0]" @pause="videoPause"></video>
					</view>
					<view class="poster" v-if="controls">
						<image class="image" :src="imgUrls[0]"></image>
					</view>
					<view class="stop" v-if="controls" @tap="bindPause">
						<image class="image" src="../../static/images/stop.png"></image>
					</view>
				</view>
			</swiper-item>

			<block v-for="(item,index) in imgUrls" :key='index'>
				<swiper-item>
					<image :src="item" class="slide-image" />
				</swiper-item>
			</block>
		</swiper>
	</view>
</template>

<script>
	export default {
		props: {
			imgUrls: {
				type: Array,
				default: function() {
					return [];
				}
			},
			videoline: {
				type: String,
				value: ""
			}
		},
		data() {
			return {
				indicatorDots: true,
				circular: true,
				autoplay: true,
				interval: 3000,
				duration: 500,
				currents: "1",
				controls: true,
				isPlay: true,
				videoContext: null
			};
		},
		mounted() {
			if (this.videoline) {
				this.imgUrls.shift()
				this.videoContext = uni.createVideoContext('myVideo', this); // 创建videoContext
			}
		},
		methods: {
			videoPause(e) {},
			bindPause: function() { 
				if (this.videoContext) {
					this.videoContext.play(); // 调用play方法
					this.$set(this, 'controls', false);
					this.autoplay = false;
				}
			},
			change: function(e) {
				this.$set(this, 'currents', e.detail.current + 1);
			}
		}
	}
</script>

<style scoped lang="scss">
	.product-bg {
		width: 100%;
		height: 750rpx;
		position: relative;
	}

	.product-bg swiper {
		width: 100%;
		height: 100%;
		position: relative;
	}

	.product-bg .slide-image {
		width: 100%;
		height: 100%;
	}

	.product-bg .pages {
		position: absolute;
		background-color: #fff;
		height: 34rpx;
		padding: 0 10rpx;
		border-radius: 3rpx;
		right: 30rpx;
		bottom: 30rpx;
		line-height: 34rpx;
		font-size: 24rpx;
		color: #050505;
	}

	#myVideo {
		width: 100%;
		height: 100%
	}

	.product-bg .item {
		position: relative;
		width: 100%;
		height: 100%;
	}

	.product-bg .item .poster {
		position: absolute;
		top: 0;
		left: 0;
		height: 750rpx;
		width: 100%;
		z-index: 9;
	}

	.product-bg .item .poster .image {
		width: 100%;
		height: 100%;
	}

	.product-bg .item .stop {
		position: absolute;
		top: 50%;
		left: 50%;
		width: 136rpx;
		height: 136rpx;
		margin-top: -68rpx;
		margin-left: -68rpx;
		z-index: 9;
	}

	.product-bg .item .stop .image {
		width: 100%;
		height: 100%;
	}
</style>

组件使用

import productConSwiper from '@/components/productConSwiper';
components: {
			productConSwiper,
},

sliderImage是一个图片地址数组
在这里插入图片描述

productInfo.video是视频的地址

<productConSwiper :imgUrls="sliderImage" :videoline="productInfo.video">
</productConSwiper>

http://www.kler.cn/news/325115.html

相关文章:

  • 成都睿明智科技有限公司可靠吗?
  • SpringBoot--为什么Controller是串行的?怎样才能并行?
  • uni-app之旅-day01-home页
  • Python 课程18-SQLAlchemy
  • Stable Diffusion绘画 | LCM模型:实现秒出图
  • 多旋翼无人机光伏发电站吊运技术详解
  • nodejs基于vue电子产品商城销售网站的设计与实现 _bugfu
  • 19 vue3之自定义指令Directive按钮鉴权
  • Qt --- 其他控件的介绍 --- 多元素控件
  • 【在Linux世界中追寻伟大的One Piece】验证TCP
  • 数据工程师岗位常见面试问题-1(附回答)
  • yolo自动化项目实例解析(七)自建UI--工具栏选项
  • 【JavaEE初阶】深入解析单例模式中的饿汉模式,懒汉模式的实现以及线程安全问题
  • IDEA服务启动时无法输出日志
  • 用C++游戏开发
  • 【观察】华为:构筑先进AI存力底座,引领时代更创造时代
  • 企业如何提升知识产权管理效率?
  • linux StarRocks 安装
  • linux开启wol (网络唤醒)
  • MySQL Mail服务器集成:如何配置发送邮件?
  • 信号分解降噪 | Matlab实现基于TVFEMD-IMF能量熵增量的数据降噪方法
  • 华为OD机试 - 新学校选址(Python/JS/C/C++ 2024 E卷 100分)
  • 2024icpc(Ⅱ)网络赛补题E
  • C++(list的简单实现,着重点是迭代器)
  • navicat连接postgresql的ERROR: column datlastsysoid
  • 美图AI短片创作工具MOKI全面开放 支持生成配乐、细节修改
  • Pencils Protocol 成市场新宠,生态通证$DAPP价值几何
  • 鸿蒙HarmonyOS开发生态
  • 使用vite+react+ts+Ant Design开发后台管理项目(四)
  • 巧用枚举消除条件判断