如何让 img 无法点击?我想在它上画一些东西,但当我制作 mousedown 时, mousemove 图像就在我的鼠标之后。这有可能让它留在原地吗?我知道我可以在 div 中创建它作为背景但是现在我想尝试img。感谢。
图片因为我的语言而变得更加清晰: screen
答案 0 :(得分:5)
你可以把它放在你的css中来解决你的问题:
#myImage {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
}
编辑(OP的评论):
更完整的解决方案是
#myImage {
-moz-user-select: none;
-khtml-user-select: none;
-webkit-user-select: none;
user-select: none;
-moz-user-drag: none;
-khtml-user-drag: none;
-webkit-user-drag: none;
user-drag: none;
}
(根据我的经验,两者都需要避免糟糕的用户体验)
答案 1 :(得分:0)
您可以使用与图像块保持相同位置的另一个div,您必须将其z-index设置为略高于图像。例如,
<div id="main">
<img src="01.jpg" alt="..." />
<div id="draw"> </div>
</div>
你的CSS:
#main {
position: relative;
width: 300px;
height: 300px;
overflow: hidden;
}
#main img {
position: absolute;
bottom: 0;
z-index: -1;
}
#main #draw {
width: 300px;
height: 300px;
position: absolute;
bottom: 0;
z-index: 99;
}