Javascript Onmousedown属性未检测鼠标是否正在拖动?
圣诞节到了!所以,我想做一个堆雪人的游戏,我做到了:Javascript Onmousedown属性未检测鼠标是否正在拖动?,javascript,html,Javascript,Html,圣诞节到了!所以,我想做一个堆雪人的游戏,我做到了: <img onmousedown="build(event, this)" id="head" src="head.svg"> “sm”也代表雪人。你会犯什么错误,你想要什么结果?你的问题不清楚在img之前是否调用了脚本?你缺少分号了吗?有错误吗?首先,我没有错误,但我只希望“onmousedown”属性用于拖动。第二,脚本在img之后调用,您不需要分号,但如果您喜欢,
<img onmousedown="build(event, this)" id="head" src="head.svg">
“sm”也代表雪人。你会犯什么错误,你想要什么结果?你的问题不清楚在img之前是否调用了脚本?你缺少分号了吗?有错误吗?首先,我没有错误,但我只希望“onmousedown”属性用于拖动。第二,脚本在img之后调用,您不需要分号,但如果您喜欢,可以添加分号。正如我所说,如果“onmousedown”属性不能用于拖动,那么您可以告诉我是否需要使用其他属性。
const sm = {
head: document.getElementById('head'),
body: document.getElementById('body'),
bottom: document.getElementById('bottom'),
stick1: document.getElementById('stick1'),
stick2: document.getElementById('stick2')
}
function build(event, smPart) {
x = event.clientX
y = event.clientY
smPart.style.position = 'absolute'
smPart.style.left = (x - (smPart.width / 2)).toString() + 'px'
smPart.style.top = (y - (smPart.height / 2)).toString() + 'px'
}