我正在尝试为div添加不透明度。
这是我的Jquery:
$('.redDiv').fadeIn(0, 0.5);
Run Code Online (Sandbox Code Playgroud)
我的HTML:
<div class="redDiv" style="background:red;width:20px;height:20px;"> </div>
<div class="divBlue;" style="background:blue;width:20px;height:20px;"> </div>
<div class="divBlack;" style="background:black;width:20px;height:20px;"> </div>
Run Code Online (Sandbox Code Playgroud)
有几种不同的方法可以做到这一点:
$('.redDiv').css("opacity", "0.5"); //Immediately sets opacity
$('.redDiv').fadeTo(0, 0.5); //Animates the opacity to 50% over the course of 0 milliseconds. Increase the 0 if you want to animate it.
$('.redDiv').fadeIn(); //Animates the opacity from 0 to 100%
Run Code Online (Sandbox Code Playgroud)
如果元素具有display:nonefadeTo和fadeIn都将使该元素在淡入淡出之前可见