防止选择图像和文本 [英] Preventing images and text to be selected

查看:79
本文介绍了防止选择图像和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图片被黑客入侵为背景图片(如这里)。我注意到,如果我拖动我的鼠标它,虽然,它选择了图像,以便它不能取消选择。我试过以下代码无效:

 < style type =text / css> 
html,body {
height:100%;
margin:0;
padding:0;
}
img#bg {
position:fixed;
top:0;
left:0;
width:100%;
height:100%;
}
#content {
position:relative;
z-index:1;
top:0px;
left:0px;
}
* .unselectable {
-moz-user-select:-moz-none;
-khtml-user-select:none;
-webkit-user-select:none;
-o-user-select:none;
user-select:none;
}
< / style>

任何想法?

解决方案

将这个添加到您的样式表

  .selectDisable {-webkit-user-select:none; -khtml-user-select:none; -moz-user-select:none; -o-user-select:none; user-select:none; } 

.selectEnable {-webkit-user-select:text; -khtml-user-select:text; -moz-user-select:text; -o-user-select:text;用户选择:文本; }

只需将类selectDisable添加到您的背景div ..或任何其他元素,选择发生。 EG a gadget div等等



拖拽效果发生在webkit(chrome,safari)firfox什么也没有,IE不能记得我认为它只显示一个拖动框。仍然 - 但不会选择



如果您有文本框,不要应用于整个文档,因为这样您就无法在IE中的文本框中选择文本, / p>

但是,防止拖动的方法是使用相同的selectDisable类将另一个空的div ontop覆盖到整个文档或区域。



在这里查找matey- try并选择 - 只要将类应用到您将图像作为类的地方



http://jsfiddle.net/Ma9MT/1/


I have an image being hacked in as a background image (as shown here). I've noticed that if I drag my mouse over it though, it selected the image so that it can't be deselected. I've tried the following code to no avail:

    <style type="text/css">
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
        img#bg {
            position:fixed;
            top:0;
            left:0;
            width:100%;
            height:100%;
        }
        #content {
            position:relative;
            z-index:1;
            top:0px;
            left:0px;
        }
        *.unselectable {
            -moz-user-select: -moz-none;
            -khtml-user-select: none;
            -webkit-user-select: none;
            -o-user-select: none;
            user-select: none;
        }
    </style>

Any ideas?

解决方案

Add this to your style sheet

.selectDisable {-webkit-user-select: none;  -khtml-user-select: none;   -moz-user-select: none; -o-user-select: none;    user-select: none; }

.selectEnable { -webkit-user-select: text;  -khtml-user-select: text;   -moz-user-select: text; -o-user-select: text;    user-select: text; }

Just add the class selectDisable to your background div.. or whatever other element you want to prevent any selection to occur. EG a gadget div , etc

The drag effect occurs on webkit(chrome,safari) firfox nothing at all and IE cant remember i think it shows a drag box only. still- but will not select

Dont apply to your whole document if you have text box because then you wont be able to select text inside the textbox in IE and its annoying

But the way to prevent dragging is to overlay another empty div ontop of your image with the same selectDisable class to the whole document or area.

Look here matey- try and select that- just apply the class to where ever you have your image as a class

http://jsfiddle.net/Ma9MT/1/

这篇关于防止选择图像和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆