【发布时间】:2021-03-04 01:47:38
【问题描述】:
我已经做了一个格子是javascript。我想用 every() 方法检查我的鼠标是否在它们上。我的班级有一个内置的悬停功能,但我不知道如何实现该方法。
class area {
constructor(x, y, w, h) {
this.x = x
this.y = y
this.w = w
this.h = h
this.posx = width - (x + w)
this.posy = height / row_num
}
hover(mx, my) {
if (mx > this.x && mx < this.x + this.w && my > this.y && my < this.y + this.h) {
return true
}
}
for (let i = 0; i < hovergrid.length; i++) {
if (hovergrid[i].hover(mouseX, mouseY)) {
}
const isValid = hovergrid.every(item => item.hover(mouseX, mouseY) === true)
console.log({ isValid })
<img id="displayedimage" onerror="this.onerror=null; this.style.display = 'none'" src="images/1.png">
这是我尝试过的方法,但效果不佳。有人可以给我一些提示吗?非常感谢`
const isValid = hovergrid.every(item => item.hover(mouseX, mouseY) === true)
console.log({ isValid })
`
【问题讨论】:
标签: javascript html arrays object