微信小程序用swiper组件实现仿抖音短视频上下划动整页切换视频功能demo
利用swiper组件可简单快速编写仿抖音短视频的功能 自动播放当前页视频 翻页停止播放当前页视频 并自动播放下页视频
有其他需求也可用 cover-view 添加 收藏 点赞 评论等功能
效果图:
video官方介绍: https://developers.weixin.qq.com/miniprogram/dev/component/video.html
swiper官方介绍: https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html
注: 官方一篇文档介绍, 基础库 2.4.4 以下版本, video (原生) 组件不支持在 swiper 中使用
介绍: https://developers.weixin.qq.com/miniprogram/dev/component/native-component.html
臭豆腐 腐乳 加柠檬 上代码就完了 奥利给 ! ! ! (里面有自定义导航栏的代码 但不多 参考着康康... 吼吼吼...)
wxml:
wxss:
cover-view {
width: 100%;
position: fixed;
z-index: 999;
}
cover-image {
width: 17px;
height: 17px;
margin-left: 8px;
padding-right: 20px;
position: absolute;
bottom: 11px;
}
json:
{
"navigationBarTextStyle": "white",
"navigationStyle": "custom",
"usingComponents": {}
}
js:
//获取应用实例
const app=getApp()
Page({
data: {
screenHeight: app.screenHeight,//获取屏幕高度
statusBarHeight: app.statusBarHeight,//获取状态栏高度
navBarHeight: app.navBarHeight,//获取导航栏高度
changeIndex: 0,
video: [{
id: 0,
video: ""
}, {
id: 1,
video: ""
}, {
id: 2,
video: ""
}]
},
//划动切换
slide(e) {
this.setData({
changeIndex: e.detail.current
})
console.log(e.detail.current)
}
})
app.js
App({
onLaunch: function() {
// 获取系统信息
wx.getSystemInfo({
success: (res)=> {
// 获取屏幕高度
this.screenHeight=res.screenHeight
// 获取状态栏高度
this.statusBarHeight=res.statusBarHeight
// 通过操作系统 确定自定义导航栏高度
if (res.system.substring(0, 3)=="iOS") {
this.navBarHeight=42
} else {
this.navBarHeight=44
}
}
})
}
})
总结
到此这篇关于微信小程序swiper组件实现抖音翻页切换视频功能的实例代码的文章就介绍到这了,更多相关微信小程序实现抖音翻页切换视频内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:微信小程序仿抖音视频之整屏上下切换功能的实现代码详解微信小程序Radio选中样式切换微信小程序开发之选项卡(窗口底部TabBar)页面切换微信小程序左右滑动切换页面详解及实例代码微信小程序开发之实现选项卡(窗口顶部TabBar)页面切换微信小程序仿抖音短视频切换效果的实例代码
上一篇: 上一篇:小程序接入分享指南
下一篇: 下一篇:抖音好友小程序上线当日被叫停,腾讯:因违规