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

微信小程序:多图片显示及图片点击放大,多视频显示

微信小程序:多图片显示及图片点击放大,多视频显示

  • 01 多图片显示及图片点击放大
  • 02 多视频
  • 03 全部代码

在这里插入图片描述

01 多图片显示及图片点击放大

在这里插入图片描述
在这里插入图片描述

<view><view class="title">图片:</view><block wx:if="{{photoUrlList.length==0}}"><view class="video-box-noData">无数据</view></block><block wx:if="{{photoUrlList.length > 0}}"><view class="photo-box"><block wx:for="{{photoUrlList}}" wx:for-item="item" wx:for-index="index" wx:key="index"><image class="photo-class" bindtap="previewImage" data-list="{{photoUrlList}}" data-src="{{item}}"  mode="aspectFit" src="{{item}}"></image></block></view></block></view>
//图片集合
let photoUrlList=['https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg','https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg','https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg','https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg','https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg','https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg','https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',]
//点击放大
previewImage:function(e) {var src = e.currentTarget.dataset.src; // 获取data-srcvar imgList = e.currentTarget.dataset.list;// 获取data-listwx.previewImage({current: src, // 当前显示图片的地址urls: imgList // 所有需要预览的图片是数组对象})
},

02 多视频

在这里插入图片描述

<view><view class="title">视频:</view><block wx:if="{{videoUrlList.length==0}}"><view class="video-box-noData">无数据</view></block><block wx:if="{{videoUrlList.length > 0}}"><view class="video-box"><block wx:for="{{videoUrlList}}" wx:for-item="item" wx:for-index="index" wx:key="index"><video id="myVideo" class="video-class"src="{{item}}" binderror="videoErrorCallback" show-center-play-btn='{{true}}' show-play-btn="{{true}}" controlsshow-mute-btn="{{true}}"enable-play-gesture="{{true}}"picture-in-picture-show-progress="{{true}}"show-snapshot-button="{{true}}"picture-in-picture-mode="{{['push', 'pop']}}"bindenterpictureinpicture='bindVideoEnterPictureInPicture'bindleavepictureinpicture='bindVideoLeavePictureInPicture'></video></block></view></block>
</view>
let videoUrlList=['http://data.video.iqiyi.com/videos/other/20240311/3f/9e/0424dc6e60f921fb57af60cd58133157.mp4?pv=0.2&pv=0.2','http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400','http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400','http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400','http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400','http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400','http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400',
]// 视频相关bindVideoEnterPictureInPicture() {// console.log('进入小窗模式')},bindVideoLeavePictureInPicture() {// console.log('退出小窗模式')},videoErrorCallback(e) {console.log('视频错误信息:')console.log(e.detail.errMsg)},

03 全部代码

wxml:

<view class="detailsWorking"><view class="con2"><view><view class="title">图片:</view><block wx:if="{{photoUrlList.length==0}}"><view class="video-box-noData">无数据</view></block><block wx:if="{{photoUrlList.length > 0}}"><view class="photo-box"><block wx:for="{{photoUrlList}}" wx:for-item="item" wx:for-index="index" wx:key="index"><image class="photo-class" bindtap="previewImage" data-list="{{photoUrlList}}" data-src="{{item}}"  mode="aspectFit" src="{{item}}"></image></block></view></block></view><view><view class="title">视频:</view><block wx:if="{{videoUrlList.length==0}}"><view class="video-box-noData">无数据</view></block><block wx:if="{{videoUrlList.length > 0}}"><view class="video-box"><block wx:for="{{videoUrlList}}" wx:for-item="item" wx:for-index="index" wx:key="index"><video id="myVideo" class="video-class"src="{{item}}" binderror="videoErrorCallback" show-center-play-btn='{{true}}' show-play-btn="{{true}}" controlsshow-mute-btn="{{true}}"enable-play-gesture="{{true}}"picture-in-picture-show-progress="{{true}}"show-snapshot-button="{{true}}"picture-in-picture-mode="{{['push', 'pop']}}"bindenterpictureinpicture='bindVideoEnterPictureInPicture'bindleavepictureinpicture='bindVideoLeavePictureInPicture'></video></block></view></block></view></view><button class="button" bindtap="detailed">关闭</button></view>

wxcss:

.detailsWorking {position: absolute;top: 0;left: 0;right: 0;bottom: 0;overflow: hidden;
}.detailsWorking .con2 {position: absolute;top: 42rpx;left: 20rpx;right: 20rpx;bottom: 100rpx;z-index: 99;overflow: auto;font-size: 28rpx;
}
.con2 .title{width: 100%;height: 90rpx;line-height: 90rpx;font-size: 28rpx;font-weight: 700;color: #333;
}.detailsWorking .button {position: absolute;left: 0;bottom: 0;width: 100%;height: 90rpx;line-height: 90rpx;text-align: center;font-size: 26rpx;color: #666666;padding: 0;border-top: 1px solid #f2f2f2;background-color: #fff;overflow: hidden;
}
.con2 .video-box-noData{padding: 20rpx;border: 1px solid rgb(111, 189, 134);
}
.photo-box , .video-box{padding-left: 20rpx;padding-top: 20rpx;border: 1px solid rgb(111, 189, 134);
}
.photo-class,.video-class{width: 200rpx;height: 200rpx;border: 1px solid #eeeeee;margin-right: 18rpx;margin-bottom: 18rpx;
}

js

//获取 图片、视频
photoAndVideo:function(e){let that=this;let xxx= that.data.xxxx;wx.showLoading({title:'查询中...',mask: true});//加载效果//查询数据app.get(api.xxxx,{xxx: xxx,}).then(res => {//关闭加载效果wx.hideLoading();if (res.code == 200) {let photoUrlList=res.data.photoUrlList ? res.data.photoUrlList : [];let videoUrlList=res.data.videoUrlList ? res.data.videoUrlList : [];// photoUrlList=[//     'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',//     'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',//     'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',//     'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',//     'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',//     'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',//     'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',// ]// videoUrlList=[//     'http://data.video.iqiyi.com/videos/other/20240311/3f/9e/0424dc6e60f921fb57af60cd58133157.mp4?pv=0.2&pv=0.2',//     'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400',//     'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400',//     'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400',//     'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400',//     'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400',//     'http://wxsnsdy.tc.qq.com/105/20210/snsdyvideodownload?filekey=30280201010421301f0201690402534804102ca905ce620b1241b726bc41dcff44e00204012882540400&bizid=1023&hy=SH&fileparam=302c020101042530230204136ffd93020457e3c4ff02024ef202031e8d7f02030f42400204045a320a0201000400',// ]//更新数据that.setData({photoUrlList: photoUrlList,videoUrlList: videoUrlList,})} else {//信息提示wx.showToast({title: res.msg,icon: 'none',duration: 3000})}}).catch((err) => {//关闭加载效果wx.hideLoading();//信息提示wx.showToast({title: err,icon: 'none',duration: 3000})});
},// 放大图片
previewImage:function(e) {var src = e.currentTarget.dataset.src; // 获取data-srcvar imgList = e.currentTarget.dataset.list;// 获取data-listwx.previewImage({current: src, // 当前显示图片的地址urls: imgList // 所有需要预览的图片是数组对象})
},// 视频相关
bindVideoEnterPictureInPicture() {// console.log('进入小窗模式')
},bindVideoLeavePictureInPicture() {// console.log('退出小窗模式')
},videoErrorCallback(e) {console.log('视频错误信息:')console.log(e.detail.errMsg)
},

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • git的一些使用技巧(git fetch 和 git pull的区别,git merge 和 git rebase的区别)
  • milvus的批量向量搜索
  • 数模·插值和拟合算法
  • 【Zotero插件】Zotero Tag为文献设置阅读状态 win11下相关设置
  • 上海市计算机学会竞赛平台2022年9月月赛丙组二叉树的遍历
  • 【JavaScript】 JS 的单线程和浏览器的多进程架构
  • PHP常量
  • 图灵测试:人工智能与人类沟通的界限
  • UniVue@v1.5.0版本发布:里程碑版本
  • linux学习笔记整理: 关于linux:nginx服务器 2024/7/20;
  • Ubuntu Grub引导优化
  • 基于微信小程序+SpringBoot+Vue的校园自助打印系统(带1w+文档)
  • Flowable-SpringBoot项目集成
  • idea2019版本创建JavaWeb项目并配置Tomcat步骤
  • apollo9.0park and go-adjust
  • [nginx文档翻译系列] 控制nginx
  • 【跃迁之路】【735天】程序员高效学习方法论探索系列(实验阶段492-2019.2.25)...
  • Android开发 - 掌握ConstraintLayout(四)创建基本约束
  • Android开源项目规范总结
  • Consul Config 使用Git做版本控制的实现
  • EventListener原理
  • JavaScript对象详解
  • Netty 框架总结「ChannelHandler 及 EventLoop」
  • Rancher-k8s加速安装文档
  • 安卓应用性能调试和优化经验分享
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • -- 查询加强-- 使用如何where子句进行筛选,% _ like的使用
  • 二维平面内的碰撞检测【一】
  • 扑朔迷离的属性和特性【彻底弄清】
  • 如何抓住下一波零售风口?看RPA玩转零售自动化
  • 一起来学SpringBoot | 第十篇:使用Spring Cache集成Redis
  • 用Visual Studio开发以太坊智能合约
  • 【云吞铺子】性能抖动剖析(二)
  • 国内开源镜像站点
  • # Redis 入门到精通(一)数据类型(4)
  • # 职场生活之道:善于团结
  • #[Composer学习笔记]Part1:安装composer并通过composer创建一个项目
  • $(function(){})与(function($){....})(jQuery)的区别
  • (10)工业界推荐系统-小红书推荐场景及内部实践【排序模型的特征】
  • (C++17) optional的使用
  • (Qt) 默认QtWidget应用包含什么?
  • (第9篇)大数据的的超级应用——数据挖掘-推荐系统
  • (紀錄)[ASP.NET MVC][jQuery]-2 純手工打造屬於自己的 jQuery GridView (含完整程式碼下載)...
  • (强烈推荐)移动端音视频从零到上手(上)
  • (深度全面解析)ChatGPT的重大更新给创业者带来了哪些红利机会
  • (一)硬件制作--从零开始自制linux掌上电脑(F1C200S) <嵌入式项目>
  • (原創) 物件導向與老子思想 (OO)
  • (转)EXC_BREAKPOINT僵尸错误
  • (自适应手机端)响应式新闻博客知识类pbootcms网站模板 自媒体运营博客网站源码下载
  • ****三次握手和四次挥手
  • *p++,*(p++),*++p,(*p)++区别?
  • .net core 使用js,.net core 使用javascript,在.net core项目中怎么使用javascript
  • .Net IOC框架入门之一 Unity
  • .NET 某和OA办公系统全局绕过漏洞分析
  • .NET 中使用 TaskCompletionSource 作为线程同步互斥或异步操作的事件