gpt4 book ai didi

javascript - 无法让移动图像在点击时消失

转载 作者:行者123 更新时间:2023-12-03 01:19:44 24 4
gpt4 key购买 nike

我真的不知道自己在做什么。我正在尝试学习 JS,从一开始就很顺利。我想让 float 图像在单击后消失。我认为我的代码不正确。任何意见或建议都会有帮助。

提前致谢,马里奥

这就是我用来使图像消失的方法:

 function mousePressed(){
if(dist(pagex, pageY, chip.xx, chip.yy) < chip/1){
chip=false;
}
}

最佳答案

您最好使用 onclick在 HTML 元素上,因为直接单击该元素时它将运行您的代码。无需手动检查坐标。

可以通过设置 CSS 属性 display 来隐藏图像到

请参阅此示例:

function hideMe(element){
element.style.display = 'none';
}
<img src="https://placekitten.com/408/287" onclick="hideMe(this);">

关于javascript - 无法让移动图像在点击时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51811530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com