亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

vue 實現無規則截圖

瀏覽:26日期:2022-09-30 16:38:46

大家所見到的大多數都是有規則截圖,可以應付大部分的應用場景,但是對于圖片處理,想要將規則交給用戶,普通的截圖已經滿足不了用戶了,那我們能不能前端實現圖片的任意規則截取,接下來讓我一起探討一下吧!

vue 實現無規則截圖

通過 svg 實現 圖片截取

使用svg中clipPath image標簽 通過id 映射, 動態位置polygon的坐標,實現圖片的截取

<div><div @mousemove='mousemove' @mouseup='(e) => {mouseup(e);}'> <!-- 畫布展示 --> <svg ref='blackSvg' xmlns='http://www.w3.org/2000/svg' > <defs> <clipPath id='clippath'><polygon :points='points'></polygon> </clipPath> </defs> <image xmlns:link='http://www.w3.org/1999/xlink' rel='external nofollow' preserveAspectRatio='none' ></image> </svg> <!-- 拖拽點 --> <ul class='interception'> <li v-for='item in 4' :ref='`li${item}`' :key='item' @mousedown='(e) => {mousedown(e, item);}' ></li> </ul> <!-- 底圖展示 --> <img src='https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3228549874,2173006364&fm=26&gp=0.jpg' alt='' /> <!-- 遮罩層 --> <div class='blackDiv'></div> </div> </div>css部分

<style lang='sass'>.blackDiv width: 100% height: 100% position: absolute top: 0 z-index: 2 background: rgba(0,0,0, 1).content width:300px height:300px text-align: left position: relative .blackSvgposition: absolutetop: 0z-index: 3 .blackImgeposition: absolutetop: 0left: 0width: 300pxheight: 300px .interceptionlist-style: noneposition: absolutetop: 0margin: 0padding: 0z-index: 3>li position: absolute width: 10px height: 10px background: blue border-radius: 50% cursor: pointer &:hovertransform: scale(1.2)transition-duration: .2>li:nth-child(1) top: 10px left: 10px>li:nth-child(2) top: 10px left: 100px>li:nth-child(3) top: 100px left: 100px>li:nth-child(4) top: 100px left: 10px</style><script>

export default { name: ’Canvas’, data() { return { points: ’0 0,300 0,300 300,0 300’, // 圖片展示初始化 status: false, index: 0, disX: 0, disY: 0, coordinates: { // 初始化拖拽點1: [0, 0],2: [300, 0],3: [300, 300],4: [0, 300], }, }; }, mounted() { this.$nextTick(() => { for (let key in this.coordinates) {const left = this.coordinates[key][0];const top = this.coordinates[key][1];this.$refs[`li${key}`].style.left = `${left}px`;this.$refs[`li${key}`].style.top = `${top}px`;if (key == 2 || key == 3) { this.$refs[`li${key}`].style.left = `${left - 10}px`;}if (key == 3 || key == 4) { this.$refs[`li${key}`].style.top = `${top - 10}px`;} } document.onmouseup = () => {this.status = false; }; }); }, methods: { //鼠標按下 mousedown(e, index) { this.status = true; this.index = index; this.disX = e.clientX - this.$refs[`li${index}`].offsetLeft; this.disY = e.clientY - this.$refs[`li${index}`].offsetTop; }, // 鼠標抬起 mouseup(e) { this.status = false; }, // 鼠標移動 mousemove(e) { if (this.status) {let left = e.clientX - this.disX;let top = e.clientY - this.disY;this.$refs[`li${this.index}`].style.left = `${left}px`;this.$refs[`li${this.index}`].style.top = `${top}px`;this.coordinates[this.index] = [left, top];const pointsArr = [];for (let item in this.coordinates) { pointsArr.push( Array.from(this.coordinates[item], (e) => { return e + 5; }) );}this.points = pointsArr.join(’ ’); } }, },};效果圖展示

vue 實現無規則截圖

源碼地址

github地址--> github.com/lgxin/captu…

以上就是vue 實現無規則截圖的詳細內容,更多關于vue 無規則截圖的資料請關注好吧啦網其它相關文章!

標簽: Vue
相關文章:
主站蜘蛛池模板: 亚洲一区二区福利视频 | 成人性爱视频在线观看 | 久99久爱精品免费观看视频 | 国产精品400部自产在线观看 | 国产伦精品一区二区三区视频金莲 | 中文字幕亚洲精品 | 日本中文字幕不卡免费视频 | 国产91在线chines看 | 黄色资源在线 | 免费超爽大片黄网站 | 久久久日韩精品国产成人 | 精品黄色| 婷婷精品在线 | 一级片在线观看 | 欧美一区二区三区精品影视 | 亚洲一级毛片免观看 | 91精品免费不卡在线观看 | 国产亚洲综合色就色 | 朴妮唛19禁福利视频在线 | 青青操视频在线免费观看 | 一区二区三区四区视频在线观看 | 182tv精品视频在线播放 | 2020年国产精品午夜福利在线观看 | 国产成人黄网址在线视频 | 国产制服丝袜在线 | 高清xx另类麻豆性色生活片 | 国产亚洲精品视频中文字幕 | 97超精品视频在线观看 | 黄色一级片免费观看 | 国产一级片观看 | 96精品国产高清在线看入口 | 欧美日韩国产在线观看一区二区三区 | 又黄又爽一线毛片免费观看 | 久久国产精品99久久久久久牛牛 | 99久久精品男女性高爱 | 国产 欧美 日韩在线 | 久久成人国产精品二三区 | 美女被啪全免视频软件 | 久久国产免费观看精品1 | 国产亚洲综合久久 | 欧美日韩中文一区 |