电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

vue實現旋轉木馬動畫

瀏覽:4日期:2022-09-28 09:52:44

本文實例為大家分享了vue實現旋轉木馬動畫的具體代碼,供大家參考,具體內容如下

圖片數量可為任意值都能正常處理 [1-無限個]:

<!DOCTYPE html><html><head> <title></title> <meta charset='UTF-8'> <meta http-equiv='Access-Control-Allow-Origin' content='*'> <script src='https://cdn.jsdelivr.net/npm/vue/dist/vue.js'></script> <style>html,body{ font-size: 100px;}html,body{ width: 100%; height: 100%; overflow: hidden;}.film-box{ width:100%; height: 100%;}ul{ position: relative; width: 100%; list-style: none;}ul li { position: absolute; top: 0; left: 0; z-index: 1; width:0rem; height: 0rem; text-align: center;}ul li.film-show{ transition: all 1s; width: 87rem; height: 50rem;}ul li img { /* width: 100%; */ height: 100%;}/* 左右箭頭 */.arrow { position: absolute; width: 100%; top: 50%; /* opacity: 0; */ z-index: 3;}.prev,.next { position: absolute; height: 5rem; width: 3rem; border-radius: 50%; top: 50%; margin-top: -56px; overflow: hidden; text-decoration: none;}.prev{ left: 0; background: url('./imgs/arrow-left.png') no-repeat left top; background-size: 100% 100%;}.next{ right: 0; background: url('./imgs/arrow-right.png') no-repeat right top; background-size: 100% 100%;}.filmindex{ color: #cb2e2e; font-size: 2.4rem; position: absolute; bottom: 12rem; left: 50%; transform: translateX(-50%);} </style></head><body> <div id=’app’><ul id='slide'> <li v-for=’(item,index) in films’ :key=’index’v-bind: v-bind: v-bind:data-index = ’index’ > <img v-bind:src='http://www.hdgsjgj.cn/bcjs/item.image' alt=''> </li></ul><span class='filmindex'>{{ filmCurrIndex + 1 + ’/’ + films.length}}</span><div id='arrow'> <a href='javascript:;' @click=’last’></a> <a href='javascript:;' @click=’next’></a></div> </div></body><script> var vm = new Vue({el:’#app’,data:{ films:[], filmsHideLeft:’0rem’,//控制隱藏圖片是從左上角跳出來還是從右上角跳出來 configStart:0, filmCurrIndex:2, config:[{ 'transform':'scale(0.6)', 'top': ’5rem’, 'left': ’-13rem’, 'zIndex': 2, 'backgroundColor':'#98E0AD'}, //0{ 'transform':'scale(0.8)', 'top': ’3rem’, 'left': ’13rem’, 'zIndex': 3, 'backgroundColor':'#BAD1F0'}, //1{ 'transform':'scale(1)', 'top': ’2rem’, 'left': ’45rem’, 'zIndex': 4, 'backgroundColor':'#F3DFDE'}, //2{ 'transform':'scale(0.8)', 'top': ’3rem’, 'left': ’93rem’, 'zIndex': 3, 'backgroundColor':'#BAD1F0'}, //3{ 'transform':'scale(0.6)', 'top': ’5rem’, 'left':’113rem’, 'zIndex': 2, 'backgroundColor':'#98E0AD'}, //4 ], lessNum:0,},methods:{ next(){if (this.lessNum < 5) { this.nextFilmLessFive();} else { this.nextFilm();} }, last(){if (this.lessNum < 5) { this.lastFilmLessFive();} else { this.lastFilm();} }, nextFilm(){let self = this;this.filmsHideLeft = ’185rem’;let currShowFirst = parseInt(document.querySelectorAll(’.film-show’)[0].dataset.index);// 最后一個位于正中央時按下一個不再反應console.log(currShowFirst,self.films.length)if (currShowFirst + 3 == self.films.length){ return;}// 改變DOM的顯示與隱藏if (self.configStart == 0) { self.films[currShowFirst].show = false; if (currShowFirst + 5 <= this.films.length - 1){// 正中央顯示的是倒數第二張或倒數第一張時,按下一個不需要設置哪張顯示成trueself.films[currShowFirst + 5].show = true; }}else if (self.configStart == 1) { self.films[4].show = true; self.configStart = 0;} else if(self.configStart == 2){ self.films[3].show = true; self.configStart = 1;}console.log(self.films)self.$nextTick(function(){ // 改變DOM的left,top,scale,zIndex,backgroundColor this.filmCurrIndex = (this.filmCurrIndex + 1 >= this.films.length - 1 ? this.films.length - 1 : this.filmCurrIndex + 1); self.assign();}) }, lastFilm(){let self = this;this.filmsHideLeft = ’0rem’;let currShowFirst = parseInt(document.querySelectorAll(’.film-show’)[0].dataset.index);if (currShowFirst !== 0) { self.films[currShowFirst -1].show = true; if (currShowFirst + 4 <= this.films.length -1) {// 正中央顯示的是倒數第二張或倒數第一張時,按上一個不需要設置哪張顯示成falseself.films[currShowFirst + 4].show = false; }} else { if (self.configStart == 0) {self.configStart = 1;self.films[4].show = false; } else if (self.configStart == 1) {self.configStart = 2;self.films[3].show = false; } else {// 第一個位于正中央時按上一個不再反應return; }}console.log(self.films)self.$nextTick(function(){ this.filmCurrIndex = (this.filmCurrIndex - 1) < 0 ? 0 : (this.filmCurrIndex - 1); self.assign();}) }, lastFilmLessFive(){let currShowFirst = parseInt(document.querySelectorAll(’.film-show’)[0].dataset.index);if (this.lessNum === 4) { if (!this.films[0].show) {this.films[0].show = true; } else {if (this.configStart === 2) return;if (this.configStart === 0) { this.configStart = 1;} else if (this.configStart === 1) { this.configStart = 2; this.films[3].show = false} } } else if (this.lessNum === 3) { if (this.configStart === 1) {this.configStart = 2; } else if (this.configStart === 0) {this.configStart = 1; }} else if (this.lessNum === 2) { if (this.configStart === 1) {this.configStart = 2; } }this.$nextTick(function(){ this.filmCurrIndex = (this.filmCurrIndex - 1) < 0 ? 0 : (this.filmCurrIndex - 1); this.assign();}) }, nextFilmLessFive(){let currShowFirst = parseInt(document.querySelectorAll(’.film-show’)[0].dataset.index);if (this.lessNum === 4) { if (!this.films[0].show) return; if (this.configStart === 2) {this.configStart = 1;this.films[3].show = true; } else if (this.configStart === 1) {this.configStart = 0; } else {this.films[0].show = false; } } else if (this.lessNum === 3) { if (this.configStart === 1) {this.configStart = 0; } else if (this.configStart === 2) {this.configStart = 1; }} else if (this.lessNum === 2) { if (this.configStart === 2) {this.configStart = 1; } }this.$nextTick(function(){ console.log(this.filmCurrIndex,this.films.length) this.filmCurrIndex = (this.filmCurrIndex + 1 >= this.films.length - 1 ? this.films.length - 1 : this.filmCurrIndex + 1); this.assign();}) }, assign() { let self = this;var list= document.getElementById('slide').getElementsByClassName('film-show'); //拿到所有lifor (var i = 0; i < list.length; i++){ let json = self.config[i + this.configStart]; for (var attr in json) {list[i].style[attr] = json[attr]; }} }},mounted(){ this.films = this.films.concat([ {image:’./imgs/9.jpeg’,show:true},{image:’./imgs/1.jpg’,show:true},{image:’./imgs/2.jpg’,show:true},{image:’./imgs/3.jpg’,show:true},{image:’./imgs/4.jpg’,show:true},// {image:’./imgs/5.jpg’,show:false},// {image:’./imgs/6.jpg’,show:false},// {image:’./imgs/7.jpg’,show:false},// {image:’./imgs/8.jpg’,show:false}, ]); this.$nextTick(function(){ this.lessNum = this.films.length;if (this.lessNum === 3) { this.configStart = 1; this.filmCurrIndex = 1;}if (this.lessNum === 2) { this.configStart = 2; this.filmCurrIndex = 0;}if (this.lessNum === 1) { this.configStart = 2; this.filmCurrIndex = 0;}this.assign(); }) },created(){ let rootWidth = document.documentElement.clientWidth || document.body.clientWidth; let rootDom = document.querySelector(’html’); rootDom.style.fontSize = rootWidth / 1920 * 10 + ’px’;} }); // 功能增強(以上部分已經實現了旋轉木馬): // 以下代碼實現目標:鼠標模擬移動端的左滑右滑事件,在左滑右滑中可以切換圖片 (function(){var touchDot,flagLeft = true,flagRight = true; var bodyDom = document.querySelector(’body’);bodyDom.addEventListener(’mousedown’,down,false);bodyDom.addEventListener(’mousemove’,move,false);bodyDom.addEventListener(’mouseup’,up,false);bodyDom.addEventListener(’mouseout’,up,false);function down(event){ touchDot = event.clientX; // 獲取觸摸時的原點 }function move(event){ if (touchDot !== undefined) {var touchMove = event.clientX;// 向左滑動 if (touchMove - touchDot <= -40) { if (flagLeft) {vm.nextFilm();flagLeft = false;// 鼠標未抬起之前持續左滑最多只能左滑一張圖片flagRight = true;// 鼠標左滑切換圖片后,鼠標未抬起之前可以通過再右滑切換回到之前的圖片 } else {touchDot = touchMove; }}// 向右滑動 if (touchMove - touchDot >= 40) { if (flagRight) {vm.lastFilm();flagRight = false; // 鼠標未抬起之前持續右滑最多只能右滑一張圖片flagLeft = true;// 鼠標右滑切換圖片后,鼠標未抬起之前可以通過再左滑切換回到之前的圖片 } else {touchDot = touchMove; }} }}function up(event){ // 鼠標抬起重置一切可以進行下一步操作; flagRight = true; flagLeft = true; touchDot = undefined;} }())</script></html>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 粉碎机_塑料粉碎机_塑料破碎机厂家-星标机械 | 招商帮-一站式网络营销服务|搜索营销推广|信息流推广|短视视频营销推广|互联网整合营销|网络推广代运营|招商帮企业招商好帮手 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛婚外情取证-青岛王军侦探事务所 | 板式换网器_柱式换网器_自动换网器-郑州海科熔体泵有限公司 | 天津暖气片厂家_钢制散热器_天津铜铝复合暖气片_维尼罗散热器 | 自动气象站_农业气象站_超声波气象站_防爆气象站-山东万象环境科技有限公司 | 气动球阀_衬氟蝶阀_调节阀_电动截止阀_上海沃托阀门有限公司 | 二手注塑机回收_旧注塑机回收_二手注塑机买卖 - 大鑫二手注塑机 二手光谱仪维修-德国OBLF光谱仪|进口斯派克光谱仪-热电ARL光谱仪-意大利GNR光谱仪-永晖检测 | 电动车头盔厂家_赠品头盔_安全帽批发_山东摩托车头盔—临沂承福头盔 | 深圳标识制作公司-标识标牌厂家-深圳广告标识制作-玟璟广告-深圳市玟璟广告有限公司 | 金属检测机_金属分离器_检针验针机_食品药品金属检探测仪器-广东善安科技 | 闭端端子|弹簧螺式接线头|防水接线头|插线式接线头|端子台|电源线扣+护线套|印刷电路板型端子台|金笔电子代理商-上海拓胜电气有限公司 | 国际船舶网 - 船厂、船舶、造船、船舶设备、航运及海洋工程等相关行业综合信息平台 | 清洁设备_洗地机/扫地机厂家_全自动洗地机_橙犀清洁设备官网 | 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 示波器高压差分探头-国产电流探头厂家-南京桑润斯电子科技有限公司 | 半自动预灌装机,卡式瓶灌装机,注射器灌装机,给药器灌装机,大输液灌装机,西林瓶灌装机-长沙一星制药机械有限公司 | 探伤仪,漆膜厚度测试仪,轮胎花纹深度尺厂家-淄博创宇电子 | 钢制拖链生产厂家-全封闭钢制拖链-能源钢铝拖链-工程塑料拖链-河北汉洋机械制造有限公司 | AGV无人叉车_激光叉车AGV_仓储AGV小车_AGV无人搬运车-南昌IKV机器人有限公司[官网] | 披萨石_披萨盘_电器家电隔热绵加工定制_佛山市南海区西樵南方综合保温材料厂 | 伺服电机维修、驱动器维修「安川|三菱|松下」伺服维修公司-深圳华创益 | 政府园区专业委托招商平台_助力企业选址项目快速落地_东方龙商务集团 | 真空冷冻干燥机_国产冻干机_冷冻干燥机_北京四环冻干 | WTB5光栅尺-JIE WILL磁栅尺-B60数显表-常州中崴机电科技有限公司 | 金属回收_废铜废铁回收_边角料回收_废不锈钢回收_废旧电缆线回收-广东益夫金属回收公司 | 聚丙烯酰胺_阴离子_阳离子「用量少」巩义亿腾厂家直销,售后无忧 聚合甘油__盐城市飞龙油脂有限公司 | 篮球架_乒乓球台_足球门_校园_竞技体育器材_厂家_价格-沧州浩然体育器材有限公司 | 深圳市人通智能科技有限公司| 步进电机_agv电机_伺服马达-伺服轮毂电机-和利时电机 | 葡萄酒灌装机-食用油灌装机-液体肥灌装设备厂家_青州惠联灌装机械 | 镀锌角钢_槽钢_扁钢_圆钢_方矩管厂家_镀锌花纹板-海邦钢铁(天津)有限公司 | 兰州UPS电源,兰州山特UPS-兰州万胜商贸 | SDG吸附剂,SDG酸气吸附剂,干式酸性气体吸收剂生产厂家,超过20年生产使用经验。 - 富莱尔环保设备公司(原名天津市武清县环保设备厂) | 泰国试管婴儿_泰国第三代试管婴儿费用|成功率|医院—新生代海外医疗 | 无纺布包装机|径向缠绕包装机|缠绕膜打包机-上海晏陵智能设备有限公司 | 便民信息网_家电维修,家电清洗,开锁换锁,本地家政公司 | 澳威全屋定制官网|极简衣柜十大品牌|衣柜加盟代理|全屋定制招商 百度爱采购运营研究社社群-店铺托管-爱采购代运营-良言多米网络公司 | 拉力机-拉力试验机-万能试验机-电子拉力机-拉伸试验机-剥离强度试验机-苏州皖仪实验仪器有限公司 | 衡阳耐适防护科技有限公司——威仕盾焊接防护用品官网/焊工手套/焊接防护服/皮革防护手套 |