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

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

vue實現簡易圖片左右旋轉,上一張,下一張組件案例

瀏覽:124日期:2022-12-21 09:41:59

項目需求,嵌到elementUi里的小組件,寫得不好,不喜勿噴,謝謝

父組件代碼

<template> <div> <see-attachment :filesLists=’files’ :file=’imgFile’ v-if='showmask' @hideMask=’showmask=false’></see-attachment> </div></template><script> import seeAttachment from './seeAttachment.vue'; export default { data() { return { showmask: false, imgFile: {} }; }, components: { seeAttachment }, methods: { lookImg(f) { this.showmask = true; this.imgFile = f; }, } };</script>

子組件代碼

<template> <div> <div @click='hideMask'> <div class='img_box'> <img :src='http://www.hdgsjgj.cn/bcjs/imgPath' : : @click='stopEvent' id=’img’ /> </div> </div> <div class='handleImg_box'> <div @click='prevOne'><img src='http://www.hdgsjgj.cn/static/img/prev.png' /></div> <div @click='rotate(0)'><img src='http://www.hdgsjgj.cn/static/img/turn_left.png' /></div> <div @click='rotate(1)'><img src='http://www.hdgsjgj.cn/static/img/turn_right.png' /></div> <div @click='nextOne'><img src='http://www.hdgsjgj.cn/static/img/next.png' /></div> </div> </div></template><script> export default { name: ’seeAttachment’, props: [’filesLists’, ’file’], data: function() { return { imgPath: ’’, width: 0, height: 0, imgIndex: 0 } }, mounted() { this.getImgIndex(); this.seeAttachment(this.imgIndex); }, computed: { //去掉不是圖片的附件 imgList() { const ARR = ['png', 'PNG', 'jpeg', 'JPEG', 'bmp', 'BMP', 'jpg', 'JPG', 'gif', 'GIF']; let arrs = ’’; let suffix = ’’; let type = ’’; let newList = []; this.filesLists.forEach((item) => { arrs = item.name.split(’.’); suffix = arrs[arrs.length - 1]; type = item.type ? item.type : item.raw ? item.raw.type : suffix; ARR.some(items => { if (type.includes(items)) { newList.push(item) } }) }) return newList; } }, methods: { //通過父組件傳入的file獲取當前查看的圖片index getImgIndex() { let that = this; that.imgList.forEach((item, index) => { if(that.file.id == item.id){ that.imgIndex = index; } }) }, //?藏查看?D片 hideMask() { this.$emit(’hideMask’, false); }, stopEvent(event) { //阻止冒泡事件 //取消事件冒泡 let e = event; //若省略此句,下面的e改為event,IE運行可以,但是其他瀏覽器就不兼容 if (e && e.stopPropagation) { e.stopPropagation(); } else if (window.event) { window.event.cancelBubble = true; } }, //上一?? prevOne() { if (this.imgIndex == 0) { return false; } let img = document.getElementById(’img’) img.style.transform = ’rotate(0deg)’; this.imgIndex = this.imgIndex - 1; this.seeAttachment(this.imgIndex); }, //下一?? nextOne() { let listLength = this.imgList.length - 1; if (this.imgIndex >= listLength) { return false; } let img = document.getElementById(’img’) img.style.transform = ’rotate(0deg)’; this.imgIndex = this.imgIndex + 1; this.seeAttachment(this.imgIndex); }, //右轉 rotate(t) { let img = document.getElementById(’img’) var reg = /(rotate([-+]?((d+)(deg))))/i; var wt = img.style[’-webkit-transform’], wts = wt.match(reg); var $3 = RegExp.$3; var current = $3 ? parseInt($3) : 0; if (t == 0) { current = current == 0 ? 360 : current; current = (current - 90) % 360; } else { current = (current + 90) % 360; } img.style.transform = ’rotate(’ + current + ’deg)’; }, seeAttachment(index = 0) { if (this.imgList.length == 0) { return false; } let that = this; let basePath = 'http://' + (process.env.OSS_PATH.indexOf('test') == -1 ? 'opyx-mtds-pro' : 'opyx-mtds-test') + '.oss-cn-shenzhen.aliyuncs.com/'; that.imgPath = basePath + that.imgList[index][’path’]; let img_url = basePath + that.imgList[index][’path’]; // 創建對象 var img = new Image(); // 改變圖片的src img.src = img_url; // 定時執行獲取寬高 var check = function() { // 只要任何一方大于0 // 表示已經服務器已經返回寬高 if (img.width > 0 || img.height > 0) { let wdt = document.body.offsetWidth; let hgt = document.body.offsetHeight; let ratio = 1; if (img.width > img.height && img.width > wdt * ratio) { img.height = img.height * wdt * ratio / img.width; img.width = wdt * ratio; console.log(’寬大于高’, img) } else if (img.height > img.width && img.height > hgt * ratio) { img.width = img.width * hgt * ratio / img.height; if (img.width > wdt) { img.width = wdt; } img.height = hgt * ratio; console.log(’高大于寬’, img) } else { img.height = img.height * wdt * ratio / img.width img.width = wdt * ratio console.log(’正?!? img) } that.width = img.width; that.height = img.height; clearInterval(set); } }; var set = setInterval(check, 40); }, } }</script><style lang='scss' scoped> .handleImg_box { position: fixed; bottom: 0; left: 50%; z-index: 100; margin-left: -150px; width: 300px; padding: 1rem 0; display: flex; align-items: center; justify-content: space-around; } .handleImg_box div { font-size: 0; } .handleImg_box div img { width: 3rem; }</style>

補充知識:vue圖片放大、縮小、旋轉等。僅需要兩行代碼?。?!

效果圖

vue實現簡易圖片左右旋轉,上一張,下一張組件案例

實現步驟:

1.下載Viewer組件

npm install v-viewer --save

2.在圖片顯示的頁面引用 viewer組件(一個js文件,一個css樣式文件)

import Viewer from '@/assets/js/viewer.min.js';

import ’@/assets/css/viewer.min.css’;

3.再需要點擊圖片的標簽添加點擊事件@click

<img : :src='http://www.hdgsjgj.cn/bcjs/item.publicFileURL' @click='aaa(item)' >

vue實現簡易圖片左右旋轉,上一張,下一張組件案例

說明:因為我的圖片是在集合中存的需要動態的點擊放大(點哪個放大哪個)----id很重要 aaa()方法中要用

4.@click='aaa(item)'方法

aaa(item) { var viewer = new Viewer(document.getElementById(item.publicFileURL), { url: item.publicFileURL, }); },

vue實現簡易圖片左右旋轉,上一張,下一張組件案例

以上這篇vue實現簡易圖片左右旋轉,上一張,下一張組件案例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
主站蜘蛛池模板: 换链神器官网-友情链接交换、购买交易于一体的站长平台 | 楼承板-开闭口楼承板-无锡海逵楼承板 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | VI设计-LOGO设计公司-品牌设计公司-包装设计公司-导视设计-杭州易象设计 | 自动化改造_智虎机器人_灌装机_贴标机-上海圣起包装机械 | 油缸定制-液压油缸厂家-无锡大鸿液压气动成套有限公司 | COD分析仪|氨氮分析仪|总磷分析仪|总氮分析仪-圣湖Greatlake | 济南网站建设_济南网站制作_济南网站设计_济南网站建设公司_富库网络旗下模易宝_模板建站 | 宁波普瑞思邻苯二甲酸盐检测仪,ROHS2.0检测设备,ROHS2.0测试仪厂家 | 长沙发电机-湖南发电机-柴油发电机供应厂家-长沙明邦智能科技 | 自动化展_机器人展_机床展_工业互联网展_广东佛山工博会 | 塑木弯曲试验机_铜带拉伸强度试验机_拉压力测试台-倾技百科 | 代做标书-代写标书-专业标书文件编辑-「深圳卓越创兴公司」 | 首页-瓜尔胶系列-化工单体系列-油田压裂助剂-瓜尔胶厂家-山东广浦生物科技有限公司 | 齿式联轴器-弹性联轴器-联轴器厂家-江苏诺兴传动联轴器制造有限公司 | 宿舍管理系统_智慧园区系统_房屋/房产管理系统_公寓管理系统 | 自动化改造_智虎机器人_灌装机_贴标机-上海圣起包装机械 | 衬塑设备,衬四氟设备,衬氟设备-淄博鲲鹏防腐设备有限公司 | 济南玻璃安装_济南玻璃门_济南感应门_济南玻璃隔断_济南玻璃门维修_济南镜片安装_济南肯德基门_济南高隔间-济南凯轩鹏宇玻璃有限公司 | 苏州注册公司_苏州代理记账_苏州工商注册_苏州代办公司-恒佳财税 | 氧氮氢联合测定仪-联测仪-氧氮氢元素分析仪-江苏品彦光电 | 重庆钣金加工厂家首页-专业定做监控电视墙_操作台 | 南溪在线-南溪招聘找工作、找房子、找对象,南溪综合生活信息门户! | 细砂提取机,隔膜板框泥浆污泥压滤机,螺旋洗砂机设备,轮式洗砂机械,机制砂,圆锥颚式反击式破碎机,振动筛,滚筒筛,喂料机- 上海重睿环保设备有限公司 | 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 多米诺-多米诺世界纪录团队-多米诺世界-多米诺团队培训-多米诺公关活动-多米诺创意广告-多米诺大型表演-多米诺专业赛事 | 上海心叶港澳台联考一对一培训_上海心叶港澳台联考,港澳台联考一对一升学指导 | 食安观察网 | 全自动在线分板机_铣刀式在线分板机_曲线分板机_PCB分板机-东莞市亿协自动化设备有限公司 | 工业设计,人工智能,体验式3D展示的智能技术交流服务平台-纳金网 J.S.Bach 圣巴赫_高端背景音乐系统_官网 | 直齿驱动-新型回转驱动和回转支承解决方案提供商-不二传动 | 网站建设-网站制作-网站设计-网站开发定制公司-网站SEO优化推广-咏熠软件 | 暖气片十大品牌厂家_铜铝复合暖气片厂家_暖气片什么牌子好_欣鑫达散热器 | 高中学习网-高考生信息学习必备平台 | 广州各区危化证办理_危险化学品经营许可证代办 | 冻干机(冷冻干燥机)_小型|实验型|食品真空冷冻干燥机-松源 | WTB5光栅尺-JIE WILL磁栅尺-B60数显表-常州中崴机电科技有限公司 | 酒糟烘干机-豆渣烘干机-薯渣烘干机-糟渣烘干设备厂家-焦作市真节能环保设备科技有限公司 | 柔性输送线|柔性链板|齿形链-上海赫勒输送设备有限公司首页[输送机] | 营养师网,营养师考试时间,报名入口—网站首页 | 无线遥控更衣吊篮_IC卡更衣吊篮_电动更衣吊篮配件_煤矿更衣吊篮-力得电子 |