圖片 移動(dòng)

<template>
  <div  :style="{left:`${left}px`,top:`${top}px`}"
    @mousedown.stop>
      <img  :src="url"
        @mousedown.prevent>
  </div>
</template>
<script>
export default {
  data() {
    return {
      left: 300,
      top: 50,
    };
  },
  methods: {
    startDrag(e) {
      let { clientX: startX, clientY: startY } = e;
      this._isMouseDown = true;
      const onMove = e => {
        if (!this._isMouseDown) return;
        e.stopImmediatePropagation();
        const { clientX, clientY } = e;
        const deltaX = clientX - startX;
        const deltaY = clientY - startY;
        // 移動(dòng)距離加上原始距離
        this.left += deltaX;
        this.top += deltaY;
        startX = clientX;
        startY = clientY;
      };
      const onUp = () => {
        document.removeEventListener('mousemove', onMove);
        document.removeEventListener('mouseup', onUp);
        if (!this._isMouseDown) {
          return false;
        }
      };
      document.addEventListener('mousemove', onMove);
      document.addEventListener('mouseup', onUp);
    },
  },
};
</script>
<style lang="less" scoped>
img {
  cursor: move;
}
.card {
  position: absolute;
  background: #fff;
  .ping {
    position: absolute;
    display: flex;
    .ping-1 {
      width: 180px;
      height: 72px;
      background: #fff;
      margin-top: 8px;
      display: flex;
      margin-right: 8px;
      .name {
        font-size: 20px;
        color: rgba(0, 0, 0, 0.85);
        line-height: 28px;
      }
      .score {
        color: rgba(140, 140, 140, 1);
      }
      .bac-2 {
        background-color: #13ce9f;
      }
      .bac-1 {
        background-color: #597ef7;
      }
      .bac {
        width: 48px;
        height: 48px;
        margin: 12px;
        line-height: 48px;
        text-align: center;
        color: #fff;
        border-radius: 4px;
      }
    }
  }
}
</style>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容