欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 實(shí)現(xiàn)無(wú)規(guī)則截圖

 更新時(shí)間:2021年04月15日 10:35:52   作者:渺小塵埃  
這篇文章主要介紹了vue 實(shí)現(xiàn)無(wú)規(guī)則截圖的方法,幫助大家更好的理解和學(xué)習(xí)使用vue框架,感興趣的朋友可以了解下

大家所見(jiàn)到的大多數(shù)都是有規(guī)則截圖,可以應(yīng)付大部分的應(yīng)用場(chǎng)景,但是對(duì)于圖片處理,想要將規(guī)則交給用戶,普通的截圖已經(jīng)滿足不了用戶了,那我們能不能前端實(shí)現(xiàn)圖片的任意規(guī)則截取,接下來(lái)讓我一起探討一下吧!

通過(guò) svg 實(shí)現(xiàn) 圖片截取

使用svg中clipPath image標(biāo)簽 通過(guò)id 映射, 動(dòng)態(tài)位置polygon的坐標(biāo),實(shí)現(xiàn)圖片的截取

    <div>
        <div class="content" @mousemove="mousemove" @mouseup="(e) => {mouseup(e);}">
          <!-- 畫布展示 -->
          <svg
            ref="blackSvg"
            class="blackSvg"
            xmlns="http://www.w3.org/2000/svg"
            width="300"
            height="300"
          >
            <defs>
              <clipPath id="clippath">
                <polygon :points="points"></polygon>
              </clipPath>
            </defs>
            <image
              xmlns:link="http://www.w3.org/1999/xlink"
               rel="external nofollow" 
              width="300"
              height="300"
              preserveAspectRatio="none"
              style="clip-path: url(#clippath)"
            ></image>
          </svg>
          <!-- 拖拽點(diǎn) -->
          <ul class="interception">
            <li
              v-for="item in 4"
              :ref="`li${item}`"
              :key="item"
              @mousedown="(e) => {mousedown(e, item);}"
            ></li>
          </ul>
          <!-- 底圖展示 -->
          <img
            class="blackImge"
            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
    .blackSvg
        position: absolute
        top: 0
        z-index: 3
    .blackImge
        position: absolute
        top: 0
        left: 0
        width: 300px
        height: 300px
    .interception
        list-style: none
        position: absolute
        top: 0
        margin: 0
        padding: 0
        z-index: 3
        >li
            position: absolute
            width: 10px
            height: 10px
            background: blue
            border-radius: 50%
            cursor: pointer
            &:hover
                transform: 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: { // 初始化拖拽點(diǎn)
        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: {
    //鼠標(biāo)按下
    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;
    },
    // 鼠標(biāo)抬起
    mouseup(e) {
      this.status = false;
    },
    // 鼠標(biāo)移動(dòng)
    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(' ');
      }
    },
  },
};

效果圖展示

源碼地址

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

以上就是vue 實(shí)現(xiàn)無(wú)規(guī)則截圖的詳細(xì)內(nèi)容,更多關(guān)于vue 無(wú)規(guī)則截圖的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Vue項(xiàng)目環(huán)境搭建詳細(xì)總結(jié)

    Vue項(xiàng)目環(huán)境搭建詳細(xì)總結(jié)

    這篇文章主要為大家介紹了Vue項(xiàng)目環(huán)境搭建總結(jié)篇,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-09-09
  • Vue3項(xiàng)目pc端瀏覽器樣式正常但移動(dòng)端部分樣式失效問(wèn)題的解決方法

    Vue3項(xiàng)目pc端瀏覽器樣式正常但移動(dòng)端部分樣式失效問(wèn)題的解決方法

    這篇文章主要介紹了Vue3項(xiàng)目pc端瀏覽器樣式正常但移動(dòng)端部分樣式失效問(wèn)題的解決方法,文中通過(guò)圖文講解的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下
    2024-07-07
  • Vue+Echarts報(bào)錯(cuò)Cannot?set?properties?of?undefined?(setting?‘plate‘)

    Vue+Echarts報(bào)錯(cuò)Cannot?set?properties?of?undefined?(settin

    這篇文章主要介紹了Vue+Echarts報(bào)錯(cuò)Cannot?set?properties?of?undefined?(setting?‘plate‘)的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • JS圖片懶加載庫(kù)VueLazyLoad詳解

    JS圖片懶加載庫(kù)VueLazyLoad詳解

    這篇文章主要為大家介紹了JS圖片懶加載庫(kù)VueLazyLoad示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-02-02
  • vue?請(qǐng)求攔截器的配置方法詳解

    vue?請(qǐng)求攔截器的配置方法詳解

    這篇文章主要為大家介紹了vue?請(qǐng)求攔截器的配置方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-01-01
  • vue2.0開(kāi)發(fā)實(shí)踐總結(jié)之入門篇

    vue2.0開(kāi)發(fā)實(shí)踐總結(jié)之入門篇

    這篇文章主要為大家總結(jié)了vue2.0開(kāi)發(fā)實(shí)踐之入門,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Vue之組件的自定義事件詳解

    Vue之組件的自定義事件詳解

    這篇文章主要為大家介紹了Vue之組件的自定義事件,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • vue prop傳值類型檢驗(yàn)方式

    vue prop傳值類型檢驗(yàn)方式

    這篇文章主要介紹了vue prop傳值類型檢驗(yàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • Vue Element校驗(yàn)validate的實(shí)例

    Vue Element校驗(yàn)validate的實(shí)例

    這篇文章主要介紹了Vue Element校驗(yàn)validate的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-09-09
  • axios二次封裝的詳細(xì)過(guò)程與跨域問(wèn)題

    axios二次封裝的詳細(xì)過(guò)程與跨域問(wèn)題

    通常我們的項(xiàng)目會(huì)越做越大,頁(yè)面也會(huì)越來(lái)越多,隨之而來(lái)的是接口數(shù)量的增加,api統(tǒng)一管理,不管接口有多少,所有的接口都可以非常清晰,容易維護(hù),下面這篇文章主要給大家介紹了關(guān)于axios二次封裝的詳細(xì)過(guò)程與跨域問(wèn)題的相關(guān)資料,需要的朋友可以參考下
    2022-09-09

最新評(píng)論