<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>
圖片 移動(dòng)
?著作權(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ù)。
【社區(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)容
- 我們將在本教程中做什么 在本教程中,圖像移動(dòng)和旋轉(zhuǎn)等運(yùn)動(dòng)是使用著色器進(jìn)行的編輯圖像節(jié)點(diǎn) 點(diǎn)擊圖像節(jié)點(diǎn)上的“編輯”按...
- bounds方法設(shè)置圖片大小注意事項(xiàng) bounds是結(jié)構(gòu)體CGRect需要用CGRect接收而不能用CGSize接...
- WZXKaiYanDemo:仿淘寶一個(gè)小demo,喜歡或有用的碼友可以看一下.