DDR爱好者之家 Design By 杰米

一直以为抖音短视频切换假如用小程序做的话应该是比较简单的,直接用swiper实现就好,但在实际写的过程中才发现没那么简单,要控制的逻辑还是挺多的。

还是先看效果

微信小程序仿抖音短视频切换效果的实例代码

体验路径

自定义组件系列》》仿抖音短视频切换

微信小程序仿抖音短视频切换效果的实例代码

代码逻辑

直接调用自定义的swiper组件就好
调用代码
js

const videoList = []
Page({
 data: {
  videoList,
  activeId:2,
  isPlaying:true
 },
 onLoad() {
  var that = this
  wx.getSystemInfo({
   success: 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"
   }, {
    id: 2,
    title: "莱万多夫斯基",
    desc: "莱万多夫斯基逆天五子登科",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851322674828.mp4"
   }, {
    id: 3,
    title: "驾考那些事",
    desc: "半坡起步是多难",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851312271309.mp4"
   }, {
    id: 4,
    title: "小美女",
    desc: "蹦蹦跳跳",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851307588534.mp4"
   }, {
    id: 5,
    title: "黄渤",
    desc: "中国女排发布会,黄渤与巩俐中国女排发布会,黄渤与巩俐",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851354869410.mp4"
   }, {
    id: 6,
    title: "莱万多夫斯基",
    desc: "莱万多夫斯基逆天五子登科",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851322674828.mp4"
   }, {
    id: 7,
    title: "驾考那些事",
    desc: "半坡起步是多难",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851312271309.mp4"
   }, {
    id: 8,
    title: "小美女",
    desc: "蹦蹦跳跳",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851307588534.mp4"
   }, {
    id: 9,
    title: "黄渤",
    desc: "中国女排发布会,黄渤与巩俐中国女排发布会,黄渤与巩俐",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851354869410.mp4"
   }, {
    id: 10,
    title: "莱万多夫斯基",
    desc: "莱万多夫斯基逆天五子登科",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851322674828.mp4"
   }, {
    id: 11,
    title: "驾考那些事",
    desc: "半坡起步是多难",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851312271309.mp4"
   }, {
    id: 12,
    title: "小美女",
    desc: "蹦蹦跳跳",
    url: "https://6e6f-normal-env-ta6pc-1300924598.tcb.qcloud.la/video-swiper/1589851307588534.mp4"
   }]
  })
 },
 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;top:{{systemInfo.screenHeight/2-40/2}}px" src="/UploadFiles/2021-04-02/player.png">

wxss

@import '../common.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-top: 0.5px solid white;
 bottom: 0;
}
.viewTab{
 color: white;
}

总结

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米

P70系列延期,华为新旗舰将在下月发布

3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。

而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?

根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。