Vic*_*tor 51
使用用户选择属性:
img{
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
Run Code Online (Sandbox Code Playgroud)
orl*_*rlp 14
您可以尝试这个(这不适用于所有浏览器):
img::-moz-selection {
background-color: transparent;
color: #000;
}
img::selection {
background-color: transparent;
color: #000;
}
Run Code Online (Sandbox Code Playgroud)
或者您可以使用<div>具有适当宽度和高度的a并在其上使用CSS背景图像.例如,我在我的网站上使用它:
<div id="header"></div>
#header {
height: 79px;
width: 401px;
background: url(http://nclabs.org/images/header.png) no-repeat;
}
Run Code Online (Sandbox Code Playgroud)
最后,您可以使用Javascript以编程方式禁用它.
img {
-khtml-user-select: none;
-o-user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
user-select: none;
}
Run Code Online (Sandbox Code Playgroud)
禁用了DOM元素上的突出显示:
function disableSelection(target){
if (typeof target.onselectstart!="undefined") // if IE
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") // if Firefox
target.style.MozUserSelect="none";
else // others
target.onmousedown=function(){return false;}
target.style.cursor = "default";
}
Run Code Online (Sandbox Code Playgroud)
像这样使用它:
disableSelection(document.getElementById("my_image"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26968 次 |
| 最近记录: |