本文介绍了使用jQuery设置DIV及其内容的透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery设置HTML DIV元素及其内容的透明度的最佳方法是什么?
What is the best way to set the transparency of a HTML DIV element and its contents using jQuery?
推荐答案
$('#my_element').css({ 'opacity' : 0.7 });
您是否还想实际上为每个包含的元素设置不透明度,还是只是希望它像子元素具有相同的不透明度一样出现"?
Do you want to actually set the opacity to each of the contained elements as well, or you just want it to 'appear' as if the child elements have the same opacity?
作为我的问题的一个示例,如果您想要某种可以设置一个元素的元素以及每个子元素,则可以执行以下操作
As an example to my question, if you wanted something that sets an element, and each of the children elements, you could do something like this
html
<div id="my_element">
<div>
lorem
</div>
<div>
ipsum
</div>
</div>
jquery
$('#my_element').children().
css({ 'opacity' : 0.25 }).
end().
css({ 'opacity' : 0.25 });
希望这会有所帮助.干杯.
Hope this helps. Cheers.
这篇关于使用jQuery设置DIV及其内容的透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!