当前位置:网站首页>Sliding screen switching on uniapp supports video and image rotation, similar to Tiktok effect
Sliding screen switching on uniapp supports video and image rotation, similar to Tiktok effect
2022-07-28 08:35:00 【1024 little god】
Implementation method :
swiper Nested in swiper, By giving swiper Set custom properties , Determine whether the data type is picture or video , So as to control the effect of automatic video playback and picture rotation :

Code :
<template>
<swiper class="swiper" :vertical="true" @change="change" @touchstart="touchStart" @touchend="touchEnd">
<block v-for="item of videoList" :key="item.id">
<swiper-item ref="swiperItem" data-type="video" class="swiper-item" v-if="item.type === 'video'">
<videoPlayer :video="item" ref="player"></videoPlayer>
</swiper-item>
<swiper-item ref="swiperItem" data-type="img" v-else>
<swiper :style="{height:screenHeight+'px'}" class="img-boxs" circular :indicator-dots="true"
:autoplay="true" :current="currentImgIndex" @change="changeswiper">
<swiper-item v-for="(item, index) in item.imgList" :key="index">
<image :src="item" mode="scaleToFill" class="swiper-img" :indicator-dots="true"></image>
</swiper-item>
</swiper>
</swiper-item>
</block>
</swiper>
</template>
<script>
import videoPlayer from "./components/videoPlayer.vue"
var time = null
export default {
props: ["myList"],
components: {
videoPlayer,
},
name: "video-list",
data() {
return {
videoList: [{
id: 7,
type: "image",
imgList: [
'https://img-blog.csdnimg.cn/img_convert/4ce460a31366926464acc88c991721d9.jpeg',
'https://img-blog.csdnimg.cn/img_convert/a8d701d5adc9008ca018905f43c34145.jpeg',
'https://img-blog.csdnimg.cn/img_convert/3090b46bd91e5c7ee5d78d988fbae0bd.jpeg',
"https://img-blog.csdnimg.cn/img_convert/08acb513a12e1d7d654cc43cf4e2ee48.jpeg",
"https://img-blog.csdnimg.cn/img_convert/eebf7eefba5849ef9788e32c148061c8.jpeg"
],
}, {
id: 1,
type: "video",
preImg: "http://p1-q.mafengwo.net/s16/M00/8D/4D/CoUBUmFZOWKAA8mQAA8Oww0vs7k240.jpg",
src: "https://txmov2.a.yximgs.com/upic/2020/03/14/16/BMjAyMDAzMTQxNjIwMDlfMTI0OTQzNzMzOV8yNDk0OTExNDY1NF8xXzM=_b_B8cf5a4391531e161385a32cdadfef87c.mp4"
},
{
id: 8,
type: "image",
imgList: [
'https://img-blog.csdnimg.cn/img_convert/4ce460a31366926464acc88c991721d9.jpeg',
'https://img-blog.csdnimg.cn/img_convert/a8d701d5adc9008ca018905f43c34145.jpeg',
'https://img-blog.csdnimg.cn/img_convert/3090b46bd91e5c7ee5d78d988fbae0bd.jpeg',
"https://img-blog.csdnimg.cn/img_convert/08acb513a12e1d7d654cc43cf4e2ee48.jpeg",
"https://img-blog.csdnimg.cn/img_convert/eebf7eefba5849ef9788e32c148061c8.jpeg"
],
}, {
id: 2,
type: "video",
preImg: "http://b1-q.mafengwo.net/s16/M00/23/F3/CoUBUmFbN5OAGqEkAA4O0V-U1uo031.jpg",
src: "https://txmov2.a.yximgs.com/upic/2020/10/02/09/BMjAyMDEwMDIwOTAwMDlfMTIyMjc0NTk0Ml8zNjk3Mjg0NjcxOF8xXzM=_b_B28a4518e86e2cf6155a6c1fc9cf79c6d.mp4"
},
{
id: 3,
type: "video",
preImg: "http://p1-q.mafengwo.net/s16/M00/23/F4/CoUBUmFbN5WAbMikAA5cYlWno5U709.jpg",
src: "https://txmov6.a.yximgs.com/upic/2020/08/23/00/BMjAyMDA4MjMwMDMyNDRfMTYzMzY5MDA0XzM0ODI4MDcyMzQ5XzFfMw==_b_B9a1c9d4e3a090bb2815994d7f33a906a.mp4"
},
{
id: 4,
type: "video",
preImg: "http://p1-q.mafengwo.net/s18/M00/E6/C0/CoUBYGFceTyAOSBqABFXcMPFJ1w112.jpg",
src: "https://alimov2.a.yximgs.com/upic/2020/03/04/15/BMjAyMDAzMDQxNTU3MTdfMzE3MDM5OTAzXzI0NDUwNjQ1MzgxXzFfMw==_b_B53c20819cb9a2103b9805b0144f545cf.mp4"
},
{
id: 5,
type: "video",
preImg: "http://p1-q.mafengwo.net/s18/M00/E6/C0/CoUBYGFceTyAOSBqABFXcMPFJ1w112.jpg",
src: "https://txmov2.a.yximgs.com/upic/2020/07/14/16/BMjAyMDA3MTQxNjEyNDBfMTU3MDQyNjA0XzMyMzUyOTQ4NzM0XzJfMw==_b_Bd53949260b17aaa7b712526aa61e590a.mp4"
},
{
id: 6,
type: "video",
preImg: "http://p1-q.mafengwo.net/s18/M00/E6/C0/CoUBYGFceTyAOSBqABFXcMPFJ1w112.jpg",
src: "https://txmov2.a.yximgs.com/upic/2020/09/28/15/BMjAyMDA5MjgxNTAwMTlfNjk3OTM4NjUzXzM2NzQyNzU5MzA2XzFfMw==_b_B6e8aca57e704ac40b34856eb663b8d57.mp4"
},
],
screenHeight: 0,
currentImgIndex: 0
};
},
mounted() {
uni.getSystemInfo({
success: (res) => {
console.log(" The height of the page obtained from the home page :windowHeight", res.windowHeight);
this.screenHeight = res.windowHeight;
}
});
},
methods: {
change(res) {
clearTimeout(time)
this.page = res.detail.current
let swiperPre = this.$refs.swiperItem[this.page - 1]
let swiperItem = this.$refs.swiperItem[this.page]
let swiperNext = this.$refs.swiperItem[this.page + 1]
let currentType = swiperItem.$attrs["data-type"]
time = setTimeout(() => {
if (this.pageStartY > this.pageEndY) {
console.log(" Slide the current page up :" + this.page);
console.log(" Change the index of the currently displayed picture :", this.currentImgIndex);
if (currentType === "video") {
swiperItem.$children[0].playVideo()
this.pageStartY = 0
this.pageEndY = 0
} else {
console.log(" Change the index of the currently displayed picture :", this.currentImgIndex);
this.$nextTick(() => {
this.currentImgIndex = 0
})
}
if (swiperPre.$attrs["data-type"] === "video") {
swiperPre.$children[0].pauseVideo()
}
} else {
console.log(" Slide down " + this.page);
console.log(" Change the index of the currently displayed picture :", this.currentImgIndex);
if (currentType === "video") {
swiperItem.$children[0].playVideo()
this.pageStartY = 0
this.pageEndY = 0
} else {
console.log(" Change the index of the currently displayed picture :", this.currentImgIndex);
this.$nextTick(() => {
this.currentImgIndex = 0
})
}
if (swiperNext.$attrs["data-type"] === "video") {
swiperNext.$children[0].pauseVideo()
}
}
}, 1)
},
touchStart(res) {
this.pageStartY = res.changedTouches[0].pageY;
console.log(this.pageStartY);
},
touchEnd(res) {
this.pageEndY = res.changedTouches[0].pageY;
console.log(this.pageEndY);
},
changeswiper(e) {
this.currentImgIndex = e.detail.current
}
},
watch: {
myList() {
this.list = this.myList;
}
}
}
</script>
<style>
.swiper {
width: 100vw;
height: 100vh;
}
.swiper-item {
width: 100vw;
height: 100vh;
z-index: 9;
}
.swiper-img {
width: 100%;
height: 100%;
}
.img-boxs {
/* height: 100%; */
}
/* .left-box {
z-index: 20;
position: absolute;
bottom: 50px;
left: 10px;
}
.right-box {
z-index: 20;
position: absolute;
bottom: 50px;
right: 10px;
} */
</style>
边栏推荐
- [book club issue 13] Chapter 2 notes on the packaging format and coding format of video files
- Simple use of unity queue
- JS cartoon English alphabet typing game source code
- uniapp的swiper动态设置current值不生效解决办法
- 数字签名和CA证书
- Five screens, VR, projection, "Wei Xiaoli" rolled up on the intelligent cockpit
- New generation cloud native message queue (II)
- [mindspire YiDianTong robot-01] you may have seen many Knowledge Q & A robots, but this is a little different
- 2022牛客多校第二场解题报告
- Understand the propagation process of EMI electromagnetic interference through five diagrams - the influence of square wave steepness on high-frequency components, the spectrum graph from time sequenc
猜你喜欢

Half bridge buck circuit - record

5张图告诉你:同样是职场人,差距怎么这么大?

半桥BUCK电路—记录篇

See how Google uses pre training weights in target detection tasks | CVPR 2022

uniapp---- 获取当前位置的经纬度等信息的详细步骤(包含小程序)

2022 Niuke multi school first problem solving Report

UE4 engine customizes screenpass and MRT output

一键开关机电路

SQL Server查询结果导出到EXCEL表格

C#,入门教程——程序运行时的调试技巧与逻辑错误探针技术与源代码
随机推荐
EMC EMI磁珠的特性
豪华版h5俄罗斯方块小游戏源码
[mindspire YiDianTong robot-01] you may have seen many Knowledge Q & A robots, but this is a little different
Unity中队列(Queue)的简单使用
业务数字化飞速奔跑,管理数字化亟待出发
[Qt5] QT small software release
Matlab (3) matlab program flow control statement
Chairman tree review
5张图告诉你:同样是职场人,差距怎么这么大?
[chart component kit] Shanghai daoning provides developers with steema download, trial and tutorial
pyspark更改列顺序存入iceberg数据库
Prescan quick start to master the transportation elements in lesson 14, prescan
An article to understand data warehouse: metadata classification, metadata management
Enum class
PostgreSQL is the world's most advanced open source relational database
2022牛客多校第一场解题报告
Prescan quick start to master the road elements of lecture 15
Recommend a fully open source, feature rich, beautiful interface mall system
CarSim simulation quick start (10) - Modeling of braking system
Three different numbers with 0 in leetcode/ array