jQuery 应用 css 不透明度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10138232/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery applying css opacity
提问by green_arrow
I have tried to get the opacity to work in IE, I am testing in IE8 at the moment, Chrome etc works fine but IE8 is terrible.
我试图让不透明度在 IE 中工作,我目前正在 IE8 中进行测试,Chrome 等工作正常,但 IE8 很糟糕。
My code has been:
我的代码是:
$('#mydiv').animate({'opacity': '0.5'});
and
和
$('#mydiv').css('opacity', 0.5);
The opacity is applied to the images held within this div but none of the text, it's very infuriating :( can anyone help me? Thanks in advance.
不透明度应用于此 div 中保存的图像,但没有任何文本,这非常令人气愤:( 谁能帮助我?提前致谢。
采纳答案by Rony SP
try with this:
试试这个:
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=75)"; /* IE 8 */
filter: alpha(opacity=75); /* older IEs */
hope this is helpful for you
希望这对你有帮助
回答by Jonathan Joosten
$('#mydiv').fadeTo(0.5);
$('#mydiv').fadeTo(0.5);
or
或者
$('#mydiv').fadeTo(500,0.5);
$('#mydiv').fadeTo(500,0.5);
or
或者
$('#mydiv').fadeTo("slow",0.5);
$('#mydiv').fadeTo("slow",0.5);
回答by Adam
jQuery handles setting the opacity in an IE ≥ 6 compatible way for you, both when using the css("opacity", value)
and fade*()
methods. But be sure to use the jQuery 1.xlibrary which is compatible with IE 6, 7 and 8 as opposed to jQuery 2.xwhich is not (both are IE ≥ 9 compatible).
在使用css("opacity", value)
和fade*()
方法时,jQuery 会以 IE ≥ 6 兼容的方式为您处理设置不透明度。但一定要使用与 IE 6、7 和 8 兼容的jQuery 1.x库,而不是jQuery 2.x,后者不兼容(两者都兼容 IE ≥ 9)。
Here are the examples of using css("opacity", value)
and fadeTo(duration, opacity)
:
以下是使用css("opacity", value)
和的示例fadeTo(duration, opacity)
:
- jQuery 1.x: http://jsbin.com/xabexa/2/edit?html,js,output
- jQuery 2.x: http://jsbin.com/xabexa/3/edit?html,js,output
- jQuery 1.x:http: //jsbin.com/xabexa/2/edit?html,js,output
- jQuery 2.x:http: //jsbin.com/xabexa/3/edit?html,js,output
However, there are issues in IE ≤ 8 related to opacity of semi-transparent PNGs: How to solve/hack fading semi-transparent PNG bug in IE8?
但是,IE ≤ 8 中存在与半透明 PNG 的不透明度相关的问题: 如何解决/破解 IE8 中的褪色半透明 PNG 错误?
回答by Naigel
IE8 does'nt apply opacity to elements withoute a layout. See this answer Opacity CSS not working in IE8
IE8 不会对没有布局的元素应用不透明度。请参阅此答案Opacity CSS not working in IE8
回答by Priyank Patel
Try this
尝试这个
filter: alpha(opacity=50);
instead of
代替
opacity:0.5;