看个效果图,再决定学不学





================
好像还凑合吧

那就学起来吧~~~~~~~~~~~~~~~~~~~~~~~

<template><div class="container_box" id="video_box"><div class="van_swipe"><!--vant van-swipe 滑动组件 --><van-swipe:show-indicators="false"@change="onChange"vertical:loop="false"><van-swipe-itemv-for="(item, index) in videoList":key="index"class="product_swiper"><div class="video_container"><videoclass="video_box"width="100%"height="100%"webkit-playsinline="true"x5-playsinline=""x5-video-player-type="h5"x5-video-player-fullscreen=""playsinlinepreload="auto":poster="item.cover":src="item.url":playOrPause="playOrPause"x-webkit-airplay="allow"x5-video-orientation="portrait"@click="pauseVideo"@ended="onPlayerEnded($event)"loop="loop"></video><!-- 封面 --><imgv-show="isVideoShow"class="play"@click="playvideo":src="item.cover"/><!-- 播放暂停按钮 --><imgv-show="iconPlayShow"class="icon_play"@click="playvideo"src="../resource/icon_play.png"/></div><!-- 右侧点赞、分享功能 --><div class="tools_right"><div class="tools_r_li" @click="changeFollow(item, index)"><iclass="iconfont icon-yixianshi-":class="item.follow ? 'follow_active' : ''"></i><div class="tools_r_num">{{item.loveCount}}w</div></div><div class="tools_r_li" @click="changeShare"><i class="iconfont icon-tubiao-"></i><div class="tools_r_num">{{item.shareCount}}w</div></div></div><!-- 底部作品描述 --><div class="production_box"><div class="production_name">@{{item.name}}</div><div class="production_des"><iv-for="(list, index) in item.buyShopList" :key="index" class="production_des_i"@click="copyShopName(list.ShopUrl)">{{list.ShopName}}</i></div></div></van-swipe-item></van-swipe><!--底部操作栏--><div class="container_bottom"><divclass="bottom_tab":class="tabIndex == 0 ? 'tab_active' : ''"@click="changeTab(0)"><span class="bottom_tab_span">首页</span></div><divclass="bottom_tab":class="tabIndex == 1 ? 'tab_active' : ''"@click="changeTab(1)"><span class="bottom_tab_span">设置</span></div></div><!--分享弹框--><div class="share_hover"></div><div class="share_box" :class="showShareBox ? 'share_active' : ''"><div class="share_tips">分享到</div><ul class="share_ul"><li class="share_li pengyouquan_li"><i class="iconfont icon-pengyouquan"></i></li><li class="share_li"><i class="iconfont icon-weixin"></i></li><li class="share_li" @click="copyUrl"><i class="iconfont icon-lianjie"></i></li><div class="clear"></div></ul><div class="share_cancel" @click="cancelShare">取消</div></div></div></div>
</template>
<script>
import Vue from "vue";
import { Swipe, SwipeItem, Toast } from "vant";
Vue.use(Swipe).use(SwipeItem);
export default {name: "videoChild",data() {let u = navigator.userAgent;return {current: 0,videoList: [{url: "https://video.pearvideo.com/mp4/third/20201113/cont-1706821-15126082-111655-hd.mp4",cover: "https://image-cn2.tvcbook.com/v7/image/2020/11/13/8a7b666e-0ac8-4e34-b549-8360b1569e54.png!cover-780-439?x-oss-process=image/crop,x_0,y_72,w_1080,h_608,g_nw",follow: false,loveCount: 24,shareCount: 12,name: '智.混动',buyShopList: [{ShopName: '淘宝',ShopUrl: 'http://taobao.com'},{ShopName: '天猫',ShopUrl: 'http://taobao.com'},{ShopName: '京东',ShopUrl: 'http://taobao.com'}]},{url: "https://video.pearvideo.com/mp4/third/20201114/cont-1707004-15488237-105621-hd.mp4",cover: "https://image-cn2.tvcbook.com/daq/2020/11/12/de65881c-24b0-11eb-84ef-02420a0008fb.png!cover-780-439",follow: false,loveCount: 28,shareCount: 2,name: '用jio看世界,发现更多乐趣',buyShopList: [{ShopName: '淘宝',ShopUrl: 'http://taobao.com'},{ShopName: '天猫',ShopUrl: 'http://taobao.com'},{ShopName: '拼多多',ShopUrl: 'http://taobao.com'}]},{url: "https://video.pearvideo.com/mp4/third/20201117/cont-1707360-15126082-105138-hd.mp4",cover: "https://image-cn2.tvcbook.com/v7/thumbs/17e6bd9a691e4066b94feb8c5e0c2e84-mp4-hd/snapshots/17e6bd9a691e4066b94feb8c5e0c2e84-00053.jpg!cover-780-439",follow: false,loveCount: 48,shareCount: 23,name: '三维',buyShopList: [{ShopName: '淘宝',ShopUrl: 'http://taobao.com'},{ShopName: '天猫',ShopUrl: 'http://taobao.com'},{ShopName: '苏宁',ShopUrl: 'http://taobao.com'}]},{url: "https://video.pearvideo.com/mp4/third/20201111/cont-1706407-15488237-112532-hd.mp4",cover: "https://image-cn2.tvcbook.com/v7/image/2020/11/17/73fdf11d-ea43-4a5c-b864-e8082af3d8c0.JPG!cover-780-439?x-oss-process=image/crop,x_0,y_0,w_1920,h_1080,g_nw",follow: false,loveCount: 68,shareCount: 29,name: '世界关节炎日 MoveFree奶奶的约定',buyShopList: [{ShopName: '淘宝',ShopUrl: 'http://taobao.com'},{ShopName: '天猫',ShopUrl: 'http://taobao.com'},{ShopName: '苏宁',ShopUrl: 'http://taobao.com'}]},{url: "https://video.pearvideo.com/mp4/third/20201124/cont-1708555-15126082-104309-hd.mp4",cover: "https://image-cn2.tvcbook.com/daq/2020/11/17/7c7b0cbc-2893-11eb-9c33-02420a0008fb.png!cover-780-439",follow: false,loveCount: 168,shareCount: 129,name: '黑无节,是他们的限定狂欢日',buyShopList: [{ShopName: '淘宝',ShopUrl: 'http://taobao.com'},{ShopName: '天猫',ShopUrl: 'http://taobao.com'}]},{url: "https://video.pearvideo.com/mp4/third/20201124/cont-1708555-15126082-104309-hd.mp4",cover: "https://image-cn2.tvcbook.com/daq/2020/11/17/d73b7026-287d-11eb-9c33-02420a0008fb.png!cover-780-439",follow: false,loveCount: 18,shareCount: 1,name: '懂咖啡,也懂你的小心思',buyShopList: [{ShopName: '淘宝',ShopUrl: 'http://taobao.com'}]}],isVideoShow: true,playOrPause: true,video: null,iconPlayShow: true,isAndroid: u.indexOf("Android") > -1 || u.indexOf("Adr") > -1,isiOS: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),tabIndex: 0,showShareBox: false,loveCount: 0};},methods: {//改变菜单changeTab(index) {this.tabIndex = index;if (index === 1) {this.$router.push('/about')}},//改变收藏状态changeFollow(item, index) {this.videoList[index].follow = !this.videoList[index].follow;},//展示分享弹窗changeShare() {this.showShareBox = true;},//取消分享cancelShare() {this.showShareBox = false;},//滑动改变播放的视频onChange(index) {//改变的时候 暂停当前播放的视频let video = document.querySelectorAll("video")[this.current];video.pause();this.playOrPause = false;this.current = index;if (this.isiOS) {//ios切换直接自动播放下一个this.isVideoShow = false;this.pauseVideo();} else {//安卓播放时重置显示封面。图标等this.isVideoShow = true;this.iconPlayShow = true;}},loveCountRadom(count) {let arr = [12, 67, 34, 76.9, 12.9, 24, 1.9, 45, 4.6]return arr[count]},playvideo() {let video = document.querySelectorAll("video")[this.current];console.log(video.play());console.log("playvideo:" + this.current);this.isVideoShow = false;this.iconPlayShow = false;video.play();window.onresize = function () {video.style.width = window.innerWidth + "px";video.style.height = window.innerHeight + "px";};},pauseVideo() {//暂停\播放let video = document.querySelectorAll("video")[this.current];console.log("pauseVideo" + this.current);this.loveCount = this.loveCountRadom(this.current)if (this.playOrPause) {video.pause();this.iconPlayShow = true;} else {video.play();this.iconPlayShow = false;}this.playOrPause = !this.playOrPause;},onPlayerEnded() {//视频结束this.isVideoShow = true;this.current += this.current;},//复制当前链接copyUrl() {Toast('复制链接成功')let httpUrl = window.location.href;var oInput = document.createElement("input");oInput.value = httpUrl;document.body.appendChild(oInput);oInput.select(); // 选择对象document.execCommand("Copy"); // 执行浏览器复制命令oInput.className = "oInput";oInput.style.display = "none";},copyShopName(ShopUrl) {Toast('复制成功')}},
};
</script>
<style scoped>
.video-player {height: 100%;width: 100%;
}
.van_swipe {width: 100%;height: 100%;
}
.van-swipe {width: 100%;height: 100%;
}
.container_box {width: 100%;height: 660px;
}
.video_box {object-fit: cover !important;z-index: 999;width: 100%;height: 100%;position: absolute;left: 0;top: 0;overflow: hidden;
}
video {object-position: 0 0;
}
.icon_play {position: absolute;top: 44%;right: 0;left: 0;bottom: auto;margin: auto;z-index: 999;height: 60px;/* background: rgba(0, 0, 0, 0.5); */border-radius: 50%;
}
.play,
.platStart {position: absolute;margin: auto;top: 0;left: 0;z-index: 999;width: 100%;height: 100%;
}
/* 点赞,转发 */
.tools_right {z-index: 1001;position: absolute;right: 16px;bottom: 238px;
}
.tools_r_li {margin-bottom: 20px;color: #fff;font-size: 16px;
}
.tools_r_li:last-child {margin-bottom: 0px;
}
.icon_right {margin-bottom: 5px;font-size: 42px;display: block;text-shadow: 0px 0px 10px #9d9d9d;/*transition: .5s;*/
}
.production_box {z-index: 1001;position: absolute;/* right: 16px; */bottom: 54px;text-align: left;padding: 0 15px 15px 15px;color: #fff;width: 100%;left: 0;box-sizing: border-box;background: -webkit-linear-gradient(top,rgba(0, 0, 0, 0.2),rgba(0, 0, 0, 0)); /* Safari 5.1 - 6.0 */background: -o-linear-gradient(top,rgba(0, 0, 0, 0.2),rgba(0, 0, 0, 0)); /* Opera 11.1 - 12.0 */background: -moz-linear-gradient(top,rgba(0, 0, 0, 0.2),rgba(0, 0, 0, 0)); /* Firefox 3.6 - 15 */background: linear-gradient(to top,rgba(0, 0, 0, 0.2),rgba(0, 0, 0, 0)); /* 标准的语法 */
}
.production_name {font-weight: 700;font-size: 18px;margin-bottom: 10px;color: #fda085;
}
.production_des {overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 3;-webkit-box-orient: vertical;min-height: 62px;
}
.production_des_i {font-style: normal;font-weight: 700;color: #fda085;
}
.container_bottom {position: fixed;bottom: 0;width: 100%;background: rgba(0, 0, 0, 0.2);height: 60px;border-top: 1px solid rgba(255, 255, 255, 0.7);
}
.production_top {display: inline-block;padding: 6px;margin-bottom: 5px;background: rgba(0, 0, 0, 0.3);border-radius: 6px;margin-top: 5px;
}
.product_go {color: #fbdd21;
}
.production_title {margin-left: 4px;
}
.bottom_tab {width: 50%;text-align: center;float: left;color: #c9c9c9;padding: 10px 0;
}
.bottom_tab_span {line-height: 30px;border-bottom: 2px solid transparent;font-weight: 600;font-size: 16px;display: inline-block;/* padding: 0 4px; */transition: 0.5s all;
}
.tab_active .bottom_tab_span {border-bottom: 2px solid #fda085;color:#fda085;
}
.icon-shoucang {transition: 0.5s all;
}
.follow_active {color: #fda085;animation: showHeart 0.5s ease-in-out 0s;
}
@keyframes showHeart {0% {color: #f44;transform: scale(1);}25% {color: #fff;transform: scale(0);}80% {color: #f44;transform: scale(1.2);}100% {color: #f44;transform: scale(1);}
}
/*分享样式*/
.share_hover {position: fixed;display: none;
}
.share_box {position: fixed;bottom: -300px;width: 100%;z-index: 1002;background: #fff;border-top-left-radius: 10px;border-top-right-radius: 10px;transition: 0.5s;
}
.share_tips {text-align: center;line-height: 38px;color: #333;
}
.share_ul {box-sizing: border-box;padding: 0 25px 25px;border-bottom: 1px solid #e8e8e8;
}
.share_li {float: left;width: 33%;text-align: center;
}
.share_li i {font-size: 22px;
}
.share_cancel {text-align: center;line-height: 48px;color: #777;text-align: center;
}
.pengyouquan {color: #47d000;
}
.pengyouquan_li {animation: rotating 8s linear infinite;
}
@keyframes rotating {from {transform: rotate(0);}to {transform: rotate(360deg);}
}
.weixin {color: #20ca2e;
}
.lianjie {color: #cdcdcd;
}
.share_active {bottom: 0px;
}
</style>

代码已经放在我的 gitee,大家可以看看

同时我也在 github 上发现一位大佬做的这种效果也特别好https://github.com/maomincoding/zm_mv2

这是大佬的主要代码,感兴趣的小伙伴可以去看看。

<template><div class="home"><van-swipestyle="height: 100vh"vertical@change="onChange":show-indicators="false"><van-swipe-item><div class="main" v-if="isshow"><video-playerv-if="playerOptions.sources[0].src"class="video-player vjs-custom-skin"ref="videoPlayer":playsinline="true":options="playerOptions"></video-player><div class="footbox"><div class="foot"><p class="user">@ {{ artistName }}</p><p class="name">{{ name }}</p></div><div class="pl" @click="openPl"><van-icon name="chat" size="30" /></div></div></div></van-swipe-item><van-swipe-item><div class="main" v-if="!isshow"><video-playerv-if="playerOptions.sources[0].src"class="video-player vjs-custom-skin"ref="videoPlayer":playsinline="true":options="playerOptions"></video-player><div class="footbox"><div class="foot"><p class="user">@ {{ artistName }}</p><p class="name">{{ name }}</p></div><div class="pl" @click="openPl"><van-icon name="chat" size="30" /></div></div></div></van-swipe-item></van-swipe><van-action-sheet v-model="show" class="sheet"><van-listv-model="loading"@load="onLoad":offset="1":immediate-check="false"><div v-for="(item, index) in plist" :key="index" class="ovf pll"><div class="pl-l"><img :src="item.user.avatarUrl" alt="" /></div><div class="pl-r"><div class="name1">{{ item.user.nickname }}</div><div class="con">{{ item.content }}</div></div></div></van-list></van-action-sheet></div>
</template><script>
import { list, mv, pl } from "@request/api";
import "../video/index";
import { videoPlayer } from "vue-video-player";
export default {name: "home",data() {return {list: "",id: "",show: false,dataLength: 1,inx: 0,artistName: "",name: "",isshow: true,plist: "",loading: false,page: 10,playerOptions: {autoplay: true, //如果true,浏览器准备好时开始回放。muted: false, // 默认情况下将会消除任何音频。loop: false, // 导致视频一结束就重新开始。preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)language: "zh-CN",poster:"",aspectRatio: "16:9", // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")fluid: true, // 当true时,Video.js player将拥有流体大小。换句话说,它将按比例缩放以适应其容器。sources: [{ type: "video/mp4", src: "" }],width: document.documentElement.clientWidth,notSupportedMessage: "此视频暂无法播放,请稍后再试", //允许覆盖Video.js无法播放媒体源时显示的默认信息。controlBar: {timeDivider: true, // 分时durationDisplay: true, // 持续时间显示remainingTimeDisplay: false, // 剩余时间显示fullscreenToggle: false, //全屏按钮},},};},components: {videoPlayer,},mounted() {this.wait();},methods: {// 首次获取urlasync wait() {let id = await this.get();let res = await mv(id);// this.playerOptions.poster = this.poster;this.$set(this.playerOptions, "poster", this.poster);this.$set(this.playerOptions.sources[0], "src", res.data.url);},// 加载评论onLoad() {setTimeout(() => {this.page += 10;this.getpl();this.loading = false;}, 500);},// 获取数据get() {return list(this.dataLength).then((res) => {console.log(res.data);this.urlData = res.data;this.poster = this.urlData[this.inx].cover;this.id = this.urlData[this.inx].id;this.artistName = this.urlData[this.inx].artistName;this.name = this.urlData[this.inx].name;// return this.id;return Promise.resolve(this.id);// 等价于// return new Promise((resolve) => {//   resolve(this.id)// })});},// 封装静态数据getStatic(v) {this.id = v[this.inx].id;this.artistName = v[this.inx].artistName;this.name = v[this.inx].name;this.poster = v[this.inx].cover;return this.id;},// 获取评论getpl() {pl(this.id, this.page).then((res) => {if (document.querySelector(".van-action-sheet__content")) {document.querySelector(".van-action-sheet__content").scrollTop = 0;}this.plist = res.comments;});},// 滑动触发async onChange() {console.log(this.inx);this.isshow = !this.isshow;this.page = 10;this.getpl();if (this.inx < this.urlData.length - 1) {this.inx += 1;let id = this.getStatic(this.urlData);let res = await mv(id);this.$set(this.playerOptions.sources[0], "src", res.data.url);this.$set(this.playerOptions, "poster", this.poster);// this.playerOptions.poster = this.poster;} else {this.inx = 0;this.dataLength += 1;this.wait();}},// 打开评论列表openPl() {this.show = true;this.getpl();},},
};
</script>
<style lang="less" scoped>
.main {height: 100%;
}
.footbox {position: relative;bottom: 0;width: 95%;margin: 0 auto;display: flex;justify-content: space-between;align-items: center;
}
.user {font-size: 14px;
}
.user,
.name {text-overflow: ellipsis;overflow: hidden;white-space: nowrap;
}
.foot {width: 80%;color: #fff;font-size: 16px;z-index: 10001;
}
.pl {width: 10%;color: #fff;font-size: 16px;z-index: 10001;
}
.sheet {height: 50vh;.pll {overflow: hidden;padding: 10px;border-bottom: 1px solid #f4f4f4;.pl-l {width: 20%;float: left;}.pl-l img {width: 55%;border-radius: 50%;animation: all ds 0.5s;}@keyframes ds {from {opacity: 0;}to {opacity: 1;}}.pl-r {width: 78%;float: left;}.name1 {font-size: 14px;color: #666;font-weight: bold;margin-bottom: 5px;}.con {width: 100%;line-height: 24px;color: #333333;font-size: 14px;}}
}
</style>

代码参考文章:https://redelego.blog.csdn.net/article/details/87881899?utm_medium=distribute.pc_relevant.none-task-blog-OPENSEARCH-2.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-OPENSEARCH-2.channel_param

vue 仿照抖音视频效果(滑动切换)相关推荐

  1. vue仿抖音视频列表(兼容微信内置X5浏览器)

    vue 仿抖音视频列表(兼容微信内置X5浏览器)https://blog.csdn.net/superKM/article/details/87603255制作 仿抖音视频列表遇到很多坑,特别是安卓微 ...

  2. 微信小程序实现抖音视频效果

    当我们进行开发的时候可能会遇到需要实现抖音视频效果的需求,并且网上该效果的开源代码少,找到的开源代码代码量大,很难进行二次开发 对此我将自己的代码进行简化,仅留下可动性高的代码模块 以上是实现效果与此 ...

  3. 仿抖音视频自动播放html,vue 仿抖音视频列表(兼容微信内置X5浏览器)

    制作 仿抖音视频列表遇到很多坑,特别是安卓微信内置浏览器,让人脑壳疼,核心代码不多 便于理解 组件用到了vant 中的swiper滑动组件 h5 原生 video 属性 webkit-playsinl ...

  4. 仿抖音写上下滑动切换视频

    公司小程序要做个仿抖音上下切换视频的效果,一开始想用swiper,有资料说多了会卡.原因是video标签太多的原因,查看资料有只是用一个video标签的,滑动时切换src即可 全部代码 <tem ...

  5. 小程序如何实现抖音视频效果?

    1.wxml部分代码 ,主要是利用swiper 标签滑动切换,事件处理,具体参数说明可以去小程序官网文档看.https://developers.weixin.qq.com/miniprogram/d ...

  6. Android 仿抖音可上下滑动切换视频或图片

    支持切换图片或视频 https://gitee.com/wasadsdfa/sliding-douyin-master

  7. 微信小程序 仿抖音视频--整屏上下切换功能

    效果演示: WXML: <view class="video_box"><view bindtouchend="touchEnd" id=&q ...

  8. uniapp 小程序实现抖音视频效果

    效果图: <template><view><view class="uni-padding-wrap"><view class=" ...

  9. html5仿抖音切换效果,仿抖音视频滑动效果

    更新记录 1.6.2(2020-06-04) 优化css3动画效果 1.6.1(2020-05-23) 1.修复串音 2.新增进度条 3.新增弹幕 查看更多 scroll-video uniapp仿抖 ...

最新文章

  1. 我教你怎么玩转git
  2. css中元素居中总结
  3. 大家放松下吧,咱家先在首页呆会儿!
  4. intellij运行flink的wordcount实验-Java版本
  5. SegIntersect
  6. linuxC编程实战 my_server.c例子问题总结
  7. Python学习之==接口开发
  8. mac 系统下 刻录centos 系统到 U盘中
  9. Charles抓包工具
  10. 音频基础 - Linein和Micin的区别及使用
  11. 将Wi-Fi生成二维码
  12. MySQL_where条件查询
  13. 台式机与笔记本辐射谁大
  14. ajax选项卡解析,ajax实现的选项卡
  15. 计算机科学类专升本复习之“C语言结构体”详解(初稿)
  16. java emoji表情 乱码_java 微信昵称带有emoji 表情乱码
  17. MySQL使用存储过程批量插入百(千)万测试数据
  18. vue项目中scrollTop如何使用
  19. 移动硬盘、固态硬盘、机械硬盘总结
  20. 关于Android Studio中点9图的编译错误问题:Some file crunching failed

热门文章

  1. 2021年烟花爆竹产品涉药考试题库及烟花爆竹产品涉药考试试卷
  2. 红帽8(RHEL8)官方正版下载、安装与注册
  3. 技术开发角度浅析黑神话悟空
  4. 降噪音质好的耳机推荐,2021年降噪耳机排行!
  5. element Tooltip 提示组件修改背景颜色 箭头颜色
  6. CSP-J2021第二轮 解题分析
  7. vue实现echarts折线图 横坐标可以拖动
  8. 基于Python实现的主机远程控制
  9. 背包问题的C语言实现
  10. JasperSoft相关报错合集,持续更新