Method jQuery Fading
By jQuery, you can fade in fade-out effect elements.
jQuery fade has the following four methods:
- fadeIn ()
- fadeOut()
- fadeToggle()
- fadeTo ()
jQuery fadeIn () method
jQuery fadeIn () used to fade in the hidden elements.
grammar:
$(selector).fadeIn(speed,callback);
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast" or milliseconds.
The optional callback parameter is the name of the function performed after the completion of fading.
code:
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeIn();
$("#div2").fadeIn("slow");
$("#div3").fadeIn(3000);
});
});
</script>
</head>
<body>
<p>演示带有不同参数的 fadeIn() 方法。</p>
<button>点击这里,使三个矩形淡入</button>
<br><br>
<div id="div1" style="width:80px;height:80px;display:none;background-color:red;"></div>
<br>
<div id="div2" style="width:80px;height:80px;display:none;background-color:green;"></div>
<br>
<div id="div3" style="width:80px;height:80px;display:none;background-color:blue;"></div>
</body>
</html>
jQuery fadeOut () method
jQuery fadeOut () method to fade visible elements.
grammar:
$(selector).fadeOut(speed,callback);
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast" or milliseconds.
The optional callback parameter is the name of the function performed after the completion of fading.
code:
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeOut();
$("#div2").fadeOut("slow");
$("#div3").fadeOut(3000);
});
});
</script>
</head>
<body>
<P> fadeOut presentation with different parameters () method. </ P>
<Button> Click here to the three rectangular Fade </ Button>
<br> <br>
<div ID = "DIV1" style = "width: 80px; height: 80px; background-Color: Red;" > </ div>
<br>
<div ID = "Div2" style = "width: 80px; height: 80px; background-Color: Green;"> </ div>
<br>
<div ID = "DIV3" style = "width: 80px; height: 80px; background-Color: Blue;"> </ div>
</ body>
</html>
jQuery fadeToggle () method
jQuery fadeToggle () method can be switched between fadeIn (). fadeOut and () method.
If the element has left, then fadeToggle () will add a fade effect to the elements.
If the element is fade, then fadeToggle () will add fades to the elements.
grammar:
$(selector).fadeToggle(speed,callback);
The optional speed parameter specifies the duration of the effect. It can take the following values: "slow", "fast" or milliseconds.
The optional callback parameter is the name of the function performed after the completion of fading.
ps: code directly copy available, the introduction of self-modifying JQuery
code:
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeToggle();
$("#div2").fadeToggle("slow");
$("#div3").fadeToggle(3000);
});
});
</script>
</head>
<body>
<p> fadeToggle presentation with different parameters () method. </ P>
<Button> Click here to the three rectangular fade </ Button>
<br> <br>
<div ID = "DIV1" style = "width: 80px; height: 80px; background-Color: Red; "> </ div>
<br>
<div ID =" Div2 "style =" width: 80px; height: 80px; background-Color: Green; "> </ div>
<br>
<div ID =" DIV3 "style = "width: 80px; height: 80px; background-Color: Blue;"> </ div>
</ body>
</body>
</html>
jQuery fadeTo () method
jQuery fadeTo () method allows the gradient for a given opacity (a value between 0 and 1).
grammar:
$(selector).fadeTo(speed,opacity,callback);
speed parameter required effect when predetermined length. It can take the following values: "slow", "fast" or milliseconds.
fadeTo () method will be necessary in a fade effect opacity parameter is set to a given opacity (a value between 0 and 1).
Optional callback parameter is a function name of the function after the completion of the execution.
code:
<!DOCTYPE html>
<html>
<head>
<script src="/jquery/jquery-1.11.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").fadeTo("slow",0.15);
$("#div2").fadeTo("slow",0.4);
$("#div3").fadeTo("slow",0.7);
});
});
</script>
</head>
<body>
<p> fadeTo presentation with different parameters () method. </ P>
<Button> Click here to the three rectangular Fade </ Button>
<br> <br>
<div ID = "DIV1" style = "width: 80px; height: 80px; background-Color: Red;" > </ div>
<br>
<div ID = "Div2" style = "width: 80px; height: 80px; background-Color: Green;"> </ div>
<br>
<div ID = "DIV3" style = "width: 80px; height: 80px ; background-color: blue;"> </ div>
</body>
</html>