微信小程序仿抖音短视频切换效果的实例代码
网络编程 2021-07-04 15:03www.168986.cn编程入门
这篇文章主要介绍了微信小程序仿抖音短视频切换效果,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
一直以为抖音短视频切换假如用小程序做的话应该是比较简单的,直接用swiper实现就好,但在实际写的过程中才发现没那么简单,要控制的逻辑还是挺多的。
还是先看效果
体验路径
自定义组件系列》》仿抖音短视频切换
代码逻辑
直接调用自定义的swiper组件就好
调用代码
js
const videoList = [] Page({ data: { videoList, activeId:2, isPlaying:true }, onLoad() { var that = this wx.getSystemInfo({ suess: function(res) { that.setData({ systemInfo:res, menuButtonBoundingClientRect: wx.getMenuButtonBoundingClientRect(), }) console.log(res) }, }) this.setData({ videoList: [{ id: 1, title: "黄渤", desc: "中国女排发布会,黄渤与巩俐中国女排发布会,黄渤与巩俐", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851354869410.mp4?sign=1f636557effa496e074332e3f4b9b8aa&t=1589851461" }, { id: 2, title: "莱万多夫斯基", desc: "莱万多夫斯基逆天五子登科", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851322674828.mp4?sign=185e46cba885c4303c7cf5f8658bea9b&t=1589851482" }, { id: 3, title: "驾考那些事", desc: "半坡起步是多难", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851312271309.mp4?sign=978660c42305ec67d4c3d603c2ae5a3d&t=1589851496" }, { id: 4, title: "小美女", desc: "蹦蹦跳跳", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851307588534.mp4?sign=43cf344e83089348eeeea38d26ba51bb&t=1589851514" }, { id: 5, title: "黄渤", desc: "中国女排发布会,黄渤与巩俐中国女排发布会,黄渤与巩俐", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851354869410.mp4?sign=1f636557effa496e074332e3f4b9b8aa&t=1589851461" }, { id: 6, title: "莱万多夫斯基", desc: "莱万多夫斯基逆天五子登科", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851322674828.mp4?sign=185e46cba885c4303c7cf5f8658bea9b&t=1589851482" }, { id: 7, title: "驾考那些事", desc: "半坡起步是多难", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851312271309.mp4?sign=978660c42305ec67d4c3d603c2ae5a3d&t=1589851496" }, { id: 8, title: "小美女", desc: "蹦蹦跳跳", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851307588534.mp4?sign=43cf344e83089348eeeea38d26ba51bb&t=1589851514" }, { id: 9, title: "黄渤", desc: "中国女排发布会,黄渤与巩俐中国女排发布会,黄渤与巩俐", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851354869410.mp4?sign=1f636557effa496e074332e3f4b9b8aa&t=1589851461" }, { id: 10, title: "莱万多夫斯基", desc: "莱万多夫斯基逆天五子登科", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851322674828.mp4?sign=185e46cba885c4303c7cf5f8658bea9b&t=1589851482" }, { id: 11, title: "驾考那些事", desc: "半坡起步是多难", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851312271309.mp4?sign=978660c42305ec67d4c3d603c2ae5a3d&t=1589851496" }, { id: 12, title: "小美女", desc: "蹦蹦跳跳", url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851307588534.mp4?sign=43cf344e83089348eeeea38d26ba51bb&t=1589851514" }] }) }, onPlay(e) { // console.log("开始播放",e) }, onShowPause(e){ this.setData({ isPlaying: false }) }, onHidePause(e){ this.setData({ isPlaying: true }) }, onPause(e) { }, onEnded(e) { // console.log(e) }, onError(e) { }, onWaiting(e) { }, onTimeUpdate(e) { }, onProgress(e) { }, onChange(e) { console.log(e) console.log("id",e.detail.activeId) this.setData({ activeId:e.detail.activeId }) }, onLoadedMetaData(e) { console.log('LoadedMetaData', e) }, go2Home() { wx.navigateBack({ delta: 1, }) }, })
wxml
<mp-video-swiper class="video-swiper" video-list="{{videoList}}" bindplay="onPlay" bindpause="onPause" bindtimeupdate="onTimeUpdate" bindended="onEnded" binderror="onError" bindwaiting="onWaiting" bindprogress="onProgress" bindloadedmetadata="onLoadedMetaData" bindchange="onChange" bindshowPause="onShowPause" bindhidePause="onHidePause"></mp-video-swiper> <image wx:if="{{!isPlaying}}" class="imagePlayer" style="left:{{systemInfo.screenWidth/2-40/2}}px;:{{systemInfo.screenHeight/2-40/2}}px" src="./player.png"> </image> <view class="viewFloat"> <view class="videoTitle">{{videoList[activeId-1].title}}</view> <view class="videoDes">{{videoList[activeId-1].desc}}</view> </view> <view class="viewTabContainer"> <view class="viewTab">首页</view> <view class="viewTab">动态</view> <view class="viewTab">商品</view> <view class="viewTab">我的</view> </view>
wxss
@import '../mon.wxss'; page{ background-color: black; height: 100%; } mp-video-swiper { width: 100%; height: 100%; } .imagePlayer{ width: 40px; height: 40px; position: fixed; z-index: 1000; opacity: 0.6 } .viewFloat{ position: fixed; display: flex; z-index: 100; width: 500rpx; bottom: 60px; color: white; margin:20rpx; flex-direction: column } .videoTitle{ font-size: 18px; font-weight: 500; } .videoDes{ font-size: 14px; } .viewTabContainer{ position: fixed; display: flex; justify-content: space-around; align-items: center; flex-direction: row; width: 100%; height: 50px; border-: 0.5px solid white; bottom: 0; } .viewTab{ color: white; }
到此这篇关于微信小程序仿抖音短视频切换效果的实例代码的文章就介绍到这了,更多相关微信小程序抖音短视频切换内容请搜索狼蚁SEO以前的文章或继续浏览狼蚁网站SEO优化的相关文章希望大家以后多多支持狼蚁SEO!
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程