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

vue视频、图片自动轮播并伴随进度条

在这里插入图片描述

废话不多说直接上代

多余没用的部分自己看着删除

<template><div class="showImg"><el-carousel ref="carousel" trigger="hover" :autoplay="false" class="dimControl" :height="`${(currenInnerWith*0.375) > 3840 ? 1440 : currenInnerWith*0.375}px`"@change="carouselChange" :interval="5000" arrow="never" style="cursor: pointer;"><el-carousel-item v-for="(item,index) in imgArr" :key="item.id"><!-- @timeupdate="commonVideoUpdata(index,'video')" --><template v-if="item.banner_type==2 && isIndex==index"><video:ref="'videoRef'+index"@click="gotoBanner(item)"class="box-bg video-bg":class="'videoRef'+index":id="'videoRef'+index":muted="true"autoplay="autoplay"@mouseover="changeInterval(true)"@mouseleave="changeInterval(false)":poster="item.video_cover_url":src="item.video_url"/><span v-if="isAudioBox" class="audio-box" @click="handleAudio(index,9)"><i v-if="!isIcon" class="iconfont audio-icon" @click.stop="handleAudio(index,true)">&#xe6de;</i><i v-if="isIcon" class="iconfont audio-icon" @click.stop="handleAudio(index,false)">&#xe6db;</i></span></template><divv-else@click="gotoBanner(item)"class="box-bg"@mouseover="changeInterval(true)"@mouseleave="changeInterval(false)":style="`background-image:url(${item.url});height:${(currenInnerWith*0.375) > 3840?1440:currenInnerWith*0.375}px`"alt="#":src="item.url"/></el-carousel-item></el-carousel><div class="category-list"></div></div>
</template><script>
import axiosSrr from "@/plugins/ssr-axios";export default {props: {datas: {type: Object},isSwiperTool: {type: Boolean,default: true}},async fetch(){return axiosSrr.post("/banner/OWI_GetBanner", {banner_code: "home_banner"}).then((res) => {let retData = [];res.data.data.entities.forEach((item, i) => {let arr = {};arr.url = item.image_url;arr.id = i;arr.display_order = Number(item.display_order);arr.redirect_url = item.redirect_url;arr.banner_type = item.banner_type;arr.image_url2 = item.image_url2;arr.image_url3 = item.image_url3;arr.video_cover_url = item.video_cover_url;arr.video_url = item.video_url;retData.push(arr);});this.imgArr = retData;this.banner_duration = res.data.data.banner_duration});},data() {return {currentIndex: 0, //当前所在图片下标timer: null, //定时轮询imgArr: [],carouselData: {pic: {// master: require("@/assets/img/bitmap.png"),master: [require("@/assets/banner-bg/banner1_4k.png"),require("@/assets/banner-bg/banner1_4k.png"),require("@/assets/banner-bg/banner1_4k.png")],gifs: require("@/assets/img/dynamic_graph.png")}},screenWidth: 1440,industryData: [], //banner 下行业分类信息notice: '',currentTimeProgress: 0,isIndex: 0,intervalId: null,timeInterval: null,banner_duration: 5,isAudio: false,isIcon: false,isAudioBox: false,isCount: 0,currenInnerWith:1920,loopTimer:false,};},methods: {openTip() {},async getNotice() {let dataRet = await this.$axios.post("common_api/OWI_GetAnnouncementList")this.notice = dataRet.data.msg_list},/*** 屏幕尺寸判断*/screenChange(e) {if(!process.browser){return}let width = document.body.clientWidth;// let width = 3840;let p = "";// p=width < 2048?e[0]:(2048 <= width && width < 3840?e[1]:e[2])if (width < 2048) {p = e[0];} else if (2048 <= width && width < 3840) {p = e[1];} else {p = e[2];}return p;},//开启定时器startIntervals() {// 事件里定时器应该先清除在设置,防止多次点击直接生成多个定时器clearInterval(this.timer);this.timer = setInterval(() => {this.currentIndex++;if (this.currentIndex > this.imgArr.length - 1) {this.currentIndex = 0;}}, 5000);},// 点击左右箭头clickIcon(val) {if (val === "down") {this.currentIndex++;if (this.currentIndex === this.imgArr.length) {this.currentIndex = 0;}} else {/* 第一种写法this.currentIndex--;if(this.currentIndex < 0){this.currentIndex = this.imgArr.length-1;} */// 第二种写法if (this.currentIndex === 0) {this.currentIndex = this.imgArr.length;}this.currentIndex--;}},// 点击控制圆点changeImg(index) {this.currentIndex = index;},/*** 鼠标移入事件*/enter(e, id) {this.currentIndex = id;},//鼠标移入移出控制changeInterval(val) {if (val) {clearInterval(this.timer);} else {// this.startInterval();}},gotoBanner(val) {if (val.redirect_url) {window.open(val.redirect_url);}},getIndustryImg(val) {switch (val) {case "直播":return require("@/assets/img/cover_trade_ZhiBo.png");break;case "数字营销":return require("@/assets/img/cover_trade_ShuZiYingXiao.png");break;case "数据新闻":return require("@/assets/img/cover_trade_ShuJuXinWen.png");break;case "短视频":return require("@/assets/img/cover_trade_DuanShiPin.png");break;case "数字创意":return require("@/assets/img/cover_trade_ShuZiChuangYi@2x.png");break;case "数字文物":return require("@/assets/img/cover_trade_ShuZiWenWu@2x.png");break;case "桥梁模型":return require("@/assets/img/cover_trade_bridge@2x.png");break;case "数字信息":return require("@/assets/img/cover_trade_ShuZiXinXi.png");break;}},// 获取行业应用async getIndustryApplication() {let res = await this.$axios.post("/banner/OWI_GetBanner", {banner_code: "home_industry_application"});let arr=[]let arrSort=res.data.entities?.sort((a, b) => {return a.display_order - b.display_order;})arrSort?.map(item=>{arr.push({url: item.redirect_url,bg: item.image_url})})if (process.browser) {this.$nextTick(() => {this.industryData = arr})}},async getindustryData() {let res = await this.$axios.post("/api_source/OWI_TreeCategoryV2", {category_type: 10,current_category_show_id: "",only_show_categories: true});this.industryData = [];let industryIndex = 0;let mapData = new Map();res.data.entities.forEach(item => {let industryitem = item.self;industryitem.bg = this.getIndustryImg(industryitem.name);industryitem.url = `/web_site_front/resources/resources_model_new1?parentVal=行业应用&ClassName=${industryitem.name}&showId=${industryitem.show_id}`;industryitem.title = industryitem.name;mapData.set(industryitem.title, industryitem)//this.industryData.push(industryitem);//industryIndex++;});let freeObj = {name: '限时免费',url: 'https://www.cgpool.com/web_site_front/resourcesArea/resources_zone_info?id=300',bg: require('@/assets/img/cover_trade_Xianshi@2x.png')}mapData.set(freeObj.name, freeObj)let bridge = {name: '桥梁模型',url: 'https://www.cgpool.com/web_site_front/resourcesArea/resources_zone_info?id=290',bg: require('@/assets/img/cover_trade_bridge@2x.png')}mapData.set(bridge.name, bridge)let digiDecoration = {name: '数字家装',url: 'https://www.cgpool.com/web_site_front/resourcesArea/resources_zone_info?id=301',bg: require('@/assets/img/cover_trade_jiazhuang@2x.png')}mapData.set(digiDecoration.name, digiDecoration)let intelligentManufacture = {name: '智能制造',url: 'https://www.cgpool.com/web_site_front/resourcesArea/resources_zone_info?id=209',bg: require('@/assets/img/cover_trade_zhizao@2x.png')}mapData.set(intelligentManufacture.name, intelligentManufacture)let BAndB = {name: '民宿模型',url: 'https://www.cgpool.com/web_site_front/resourcesArea/resources_zone_info?id=292',bg: require('@/assets/img/cover_trade_minsu@2x.png')}mapData.set(BAndB.name, BAndB)// 2024 0408 需求更改// 1 限时免费 2 数字创意  3 数字家装 4 智能制造  5 桥梁模型 6 短视频let tmpArray = [];let Index1 = mapData.get("限时免费")tmpArray.push(Index1)let Index2 = mapData.get("数字创意")tmpArray.push(Index2)let Index3 = mapData.get("数字家装")tmpArray.push(Index3)let Index4 = mapData.get("智能制造")tmpArray.push(Index4)let Index5 = mapData.get("桥梁模型")tmpArray.push(Index5)let Index6 = mapData.get("民宿模型")tmpArray.push(Index6)// this.industryData = tmpArray// this.industryData.splice(1,1)// this.industryData.splice(2,0,sliceArr[0])/****/},async getBanner() {let res = await this.$axios.post("/banner/OWI_GetBanner", {banner_code: "home_banner"});this.banner_duration = res.data.banner_duration;this.imgArr=[]res.data.entities.forEach((item, i) => {let arr = {};arr.url = item.image_url;arr.id = i;arr.display_order = Number(item.display_order);arr.redirect_url = item.redirect_url;arr.banner_type = item.banner_type;arr.image_url2 = item.image_url2;arr.image_url3 = item.image_url3;arr.video_cover_url = item.video_cover_url;arr.video_url = item.video_url;this.imgArr.push(arr);});if (this.imgArr.length > 0) {this.createElChange()this.carouselChange(0)}},// 公共video获取时间commonVideoUpdata(id, type) {const self = thisif(!process.browser){return}let videoEl = document.getElementsByClassName('videoRef' + id)videoEl[0]?.addEventListener("timeupdate", function () {let el = document.querySelector(".new-indicator")if (el) {let currTime = this.currentTime //当前时间let duration = this.duration //总时间let pre = currTime / durationself.setStyleHandel(pre * 40)if (this.currentTime == this.duration) {self.handelNext()return}}})},handleToggleImg() {const self = thislet time = self.banner_duration * 1000let times = self.banner_duration * 1000 + 300clearInterval(self.intervalId);if(!process.browser){return}let el = document.querySelector(".new-indicator")if (el) {let count = 0; // 计数器// let intervalId; // 用于保存 setInterval 返回的 IDfunction executeTask() {// 执行任务的逻辑,这里假设是打印当前计数count++; // 增加计数self.setStyleHandel((40 / (time / 100)) * count)if (count === time / 100) {// 达到执行次数上限,停止定时器clearInterval(self.intervalId);}}// 每200毫秒执行一次 executeTask 函数self.intervalId = setInterval(executeTask, 100);// 5秒后停止定时器clearInterval(self.timeInterval);self.timeInterval = setInterval(() => {clearInterval(self.intervalId);clearInterval(self.timeInterval);self.handelNext()}, times);}},setStyleHandel(count) {if(!process.browser){return}let el = document.querySelector(".new-indicator")el.style.opacity = 1el.style = "background: #fff"el.style.width = `${count >= 6 ? count : 6}px`},carouselChange(e) {if (process.browser) {this.isIndex = ethis.isAudioBox = truethis.isAudio = falsethis.isIcon = falsethis.isCount = 0clearInterval(this.intervalId);clearInterval(this.timeInterval);if (process.browser) {this.$nextTick(() => {this.handleSetLeft()let el = document.querySelectorAll(".new-indicator")el?.forEach(function (indicator) {indicator.style = "width:6px"indicator.style = "opacity:0"indicator.style = "background: rgba(255, 255, 255, 0.45)"});this.imgArr?.map((item, i) => {let videoObj = this.$refs['videoRef' + i]if (Object(videoObj).length > 0) {videoObj[0].currentTime = 0setTimeout(() => {videoObj[0].play()}, 500);// let playTimer=setTimeout(() => {//   // videoObj[0].muted=false//   videoObj[0].play()// },500);// clearTimeout(playTimer);}})this.createElChange()if (Object(this.imgArr).length > 0) {el.forEach(item => {item.style = `width:${0}%`})}if (this.imgArr[e].banner_type == 1) {this.handleToggleImg()} else {this.commonVideoUpdata(e, 'video')}})}}},handleAudio(id, Boolean) {const self = thisself.isCount++// 获取 video 元素const myVideo = self.$refs['videoRef' + id];// 切换静音状态self.isAudio = !self.isAudio;// 更新视频静音状态myVideo[0].muted = self.isAudio;self.isIcon = !self.isAudio// 如果是第一次点击,并且视频正在播放,触发播放if (!self.isAudio && !myVideo[0].paused) {myVideo[0].play();}if (self.isCount == 1) {this.handleAudio(id, Boolean)}},handelNext() {if (process.server){return}this.isAudioBox = false;if (this.imgArr?.length == 1 && this.imgArr[this.isIndex]?.banner_type == 2) {this.isCount++;this.isIcon = truethis.isAudioBox = true;// 获取 video 元素const myVideo = this.$refs["videoRef" + this.isIndex];myVideo?.forEach((item, i) => {item.muted = true})}this.$refs.carousel?.next();if (this.imgArr.length == 1) {this.carouselChange(0);}},createElChange() {if (process.browser) {this.$nextTick(() => {let indicators = document.querySelectorAll(".new-indicator")// 删除这些元素indicators.forEach(function (indicator) {indicator.parentNode.removeChild(indicator);});const indicatorElement = this.$refs.carousel.$el.querySelector('.el-carousel__indicator.is-active');const newElement = document.createElement('span');newElement.textContent = '';newElement.className = 'new-indicator';newElement.style.width = `6px`;newElement.style.opacity = `0`;indicatorElement?.appendChild(newElement);})}},handleSetLeft() {if (process.browser) {this.$nextTick(() => {let element = document.querySelector(".showImg .el-carousel__indicators")let audio = document.querySelector(".showImg .audio-box")let leftDistance = element.getBoundingClientRect().left;// 输出距离if (audio) {audio.style = `left:${leftDistance + window.pageXOffset + element.clientWidth + 12}px`}})}},gotoIndustryInfo(val) {window.open(val.url);}},//进入页面后启动定时轮询mounted() {// this.getindustryData();this.getIndustryApplication();this.getBanner();this.startIntervals();this.startIntervals();this.getNotice();const self = thiswindow.addEventListener("resize", function () {self.handleSetLeft()if (!self.loopTimer) { // 使用节流机制,降低函数被触发的频率self.loopTimer = true;setTimeout(function () {window.screenWidth = window.innerWidth;self.loopTimer = false;self.$nextTick(() => {if(window.screenWidth>3840){self.currenInnerWith = 3840}else{self.currenInnerWith = window.screenWidth;}})}, 100)}});if(window.innerWidth>3840){this.currenInnerWith = 3840}else{this.currenInnerWith = window.innerWidth;}},destroyed() {// 组件销毁后解绑事件window.onresize = null;},
};
</script><style lang="scss" scoped>
$desktop2: "only screen and (max-width: 1295px)";
$desktop: "only screen and (min-width: 1296px)";
$desktop1500: "only screen and (min-width: 1500px)";
$desktop1501: "only screen and (min-width: 1501px) and (max-width: 1799px)";
$desktop1800: "only screen and (min-width: 1800px)";
$desktop_3840: "only screen and (min-width: 3840px)";
$desktop_4000: "only screen and (min-width: 4000px)";
.fontText {@media #{$desktop} {margin: 0 72px;}@media #{$desktop1500} {margin: 0 56px;}@media #{$desktop1501} {margin: 0 72px;}@media #{$desktop1800} {margin: 0 72px;}@media #{$desktop2} {margin: 0 72px;}@media #{$desktop_3840} {margin: 0px auto;}@media #{$desktop_4000} {margin: 0px auto;}margin: 0px;
}* {padding: 0;margin: 0;
}/* 清除li前面的圆点 */
li {list-style-type: none;
}.showImg {position: relative;width: 100%;// height: 587px;background: #fafafa;.box-category {// position: absolute;// top: calc(100% - 48px);// right: calc((100% - 1440px) / 2 - -220px);transform: translateY(-50%);width: 64px;height: 30px;border-radius: 15px;background-color: rgba(25, 27, 41, 0.45);line-height: 30px;text-align: center;font-size: 25px;cursor: pointer;color: rgba(255, 255, 255, 0.45);margin-right: 8px;margin-top: 14px;i {font-weight: bold;}}.box-bg {// height: 585px;width: 100%;height: 100%;max-width: 3840px;max-height: 1440px;background-repeat: no-repeat;margin: 0 auto;background-size: cover;background-repeat: no-repeat;background-position: center center;.img-box {width: 365px;position: absolute;left: calc((100% - 1440px) - -15px);z-index: 2;img {max-width: 100%;margin-top: 290px;}}}.video-bg {position: absolute;left: 50%;transform: translateX(-50%);width: 100%;height: 100%;object-fit: cover;}.audio-box {border-radius: 50%;background-color: #00000073;height: 40px;width: 40px;position: absolute;bottom: 26px;text-align: center;line-height: 40px;&:hover {background-color: rgba(255, 255, 255, 0.25);}.audio-icon {cursor: pointer;color: #fff;}}}/* 轮播图片 */
.showImg img {width: 100%;height: 100%;
}/* 箭头图标 */
.iconDiv {display: inline-block;
}.iconDiv:hover {color: #fff;
}/* 控制圆点 */
.banner-box {position: absolute;right: calc((100% - 1440px) / 2 - -70px);top: calc(100% - 63px);display: flex;
}.banner-circle {height: 20px;background-color: rgba(25, 27, 41, 0.45);border-radius: 15px;line-height: 30px;height: 30px;
}.banner-circle ul {margin: 0 20px;height: 100%;display: flex;
}.banner-circle ul li {display: inline-block;width: 14px;height: 14px;margin: 0 5px;border-radius: 7px;background-color: rgba(255, 255, 255, 0.3);cursor: pointer;align-self: center;
}.active {background-color: #ffffff !important;width: 30px !important;border-radius: 7px !important;
}@keyframes hoverLi {0% {width: 14px;}25% {width: 20px;}50% {width: 24px;}75% {width: 28px;}100% {width: 30px;}
}.active:hover {animation-name: hoverLi;animation-duration: 3s;
}.category-list {margin: 0 auto;align-self: center;
}::v-deep .el-carousel {width: 100vw;
}::v-deep .el-carousel__item {width: 100%;
}::v-deep .el-carousel__indicators {height: 40px;padding: 0 28px;background: rgba(0, 0, 0, 0.45);border-radius: 20px;bottom: 26px;// left: 75%;.el-carousel__indicator {line-height: 40px;height: 40px;margin-top: 0px;}.el-carousel__indicator--horizontal {padding: 12px 0;margin: 0 4px;}.is-active {max-width: 40px;position: relative;.new-indicator {width: 6px;height: 8px;position: absolute;top: 15px;border-radius: 6px;transition: width .3s;}.el-carousel__button {width: 40px;height: 8px;border-radius: 6px;background: rgba(255, 255, 255, 0.45);}}.el-carousel__button {width: 8px;height: 8px;border-radius: 50%;background: rgba(255, 255, 255, 0.45);margin-top: 3px;}
}.category-list {.fontText {display: flex;justify-content: space-between;// margin:0 72px;margin-top: 40px;min-width: 1296px;max-width: 3678px;font-family: Alibaba-PuHuiTi-B;.hangyeImgSty {width: 40px;height: 40px;position: relative;top: 8px;margin-right: 10px;}.Notice {width: 426px;height: 56px;background: url("@/assets/img/NoticeBg.png") no-repeat;background-size: 100% 100%;display: flex;cursor: pointer;//  align-items: center;.NoticeIcon {width: 24px;height: 24px;margin: 16px 12px 16px 24px;}span {line-height: 52px;height: 56px;}}}}</style>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 网页制作技术在未来会如何影响人们的生活?
  • Hi6274 反激式20瓦电源芯片
  • PHP场地预约共享茶室棋牌室小程序系统源码
  • el-table表头使用el-dropdown出现两个下拉框
  • Linux常用命令(简要总结)
  • android R ext4 image打包脚本介绍
  • ​1:1公有云能力整体输出,腾讯云“七剑”下云端
  • k8s安装powerjob
  • 一、单例模式
  • 【PPT笔记】1-3节 | 默认设置/快捷键/合并形状
  • 分布式服务框架zookeeper+消息队列kafka
  • 【时时三省】单元测试 简介
  • 比较HTTP/1.1、HTTP/2
  • vue2+antd实现表格合并;excel效果
  • mac电脑显示隐藏文件
  • android百种动画侧滑库、步骤视图、TextView效果、社交、搜房、K线图等源码
  • Android系统模拟器绘制实现概述
  • JavaScript 奇技淫巧
  • JavaScript异步流程控制的前世今生
  • js数组之filter
  • NLPIR语义挖掘平台推动行业大数据应用服务
  • Python 使用 Tornado 框架实现 WebHook 自动部署 Git 项目
  • 动态规划入门(以爬楼梯为例)
  • 基于Javascript, Springboot的管理系统报表查询页面代码设计
  • 力扣(LeetCode)965
  • 马上搞懂 GeoJSON
  • 事件委托的小应用
  • 数据结构java版之冒泡排序及优化
  • 一份游戏开发学习路线
  • 正则表达式小结
  • AI算硅基生命吗,为什么?
  • ​zookeeper集群配置与启动
  • ## 基础知识
  • #微信小程序:微信小程序常见的配置传旨
  • (7)摄像机和云台
  • (html5)在移动端input输入搜索项后 输入法下面为什么不想百度那样出现前往? 而我的出现的是换行...
  • (第二周)效能测试
  • (二)换源+apt-get基础配置+搜狗拼音
  • (二刷)代码随想录第15天|层序遍历 226.翻转二叉树 101.对称二叉树2
  • (附源码)ssm高校社团管理系统 毕业设计 234162
  • (附源码)ssm捐赠救助系统 毕业设计 060945
  • (论文阅读22/100)Learning a Deep Compact Image Representation for Visual Tracking
  • (三)Honghu Cloud云架构一定时调度平台
  • (四)搭建容器云管理平台笔记—安装ETCD(不使用证书)
  • (四)库存超卖案例实战——优化redis分布式锁
  • ***详解账号泄露:全球约1亿用户已泄露
  • .NET 8 中引入新的 IHostedLifecycleService 接口 实现定时任务
  • .Net Web窗口页属性
  • .NET 程序如何获取图片的宽高(框架自带多种方法的不同性能)
  • .NET 反射 Reflect
  • .NET/C# 获取一个正在运行的进程的命令行参数
  • .NET/C# 使用 SpanT 为字符串处理提升性能
  • .NET的微型Web框架 Nancy
  • .Net多线程总结
  • .Net环境下的缓存技术介绍