jQuery provides powerful tools to fade elements in and out of visibility.
Fading is an elegant way to transition content without jarring the user layout.
Search engines also digest this smoothly without penalty.
The fadeIn() method is used to slowly display a hidden element.
The fadeOut() method is used to slowly hide a visible element.
Just like hiding, you can specify a speed parameter like "slow", "fast", or milliseconds.
$("#fade-in-btn").click(function(){
$("#box").fadeIn("slow");
});
$("#fade-out-btn").click(function(){
$("#box").fadeOut(2000); // Fades out over 2 seconds
});
The fadeToggle() method intelligently switches between fading in and fading out.
If the elements are faded out, fadeToggle() will fade them in.
If the elements are faded in, fadeToggle() will fade them out.
$("button").click(function(){
$("#box").fadeToggle("fast");
});
The fadeTo() method allows fading to a specific opacity level (transparency).
Unlike the other methods, it doesn't make the element disappear completely.
The opacity value must be a number between 0.00 and 1.00.
$("button").click(function(){
// Fades the box to 30% opacity
$("#box").fadeTo("slow", 0.3);
});
Which method allows you to change an element's opacity to a precise percentage without fully hiding it?
If an element is currently visible, what will calling fadeToggle() do to it?