Introduction to jQuery
JQuery Syntax
JQuery Effects
JQuery HTML
JQuery Traversing
jQuery Fading Effects, which allow you to fade elements in and out smoothly.
jQuery has the following fade methods:
|
Method |
Description |
|---|---|
|
fadeIn() |
Fades in a hidden element |
|
fadeOut() |
Fades out a visible element |
|
fadeToggle() |
Fades in/out based on the current visibility |
|
fadeTo() |
Fades the element to a specified opacity |
The fadeIn() method is used to gradually make a hidden element visible, with a fading animation effect.
$(selector).fadeIn(speed, callback);
speed (optional): "slow", "fast", or time in milliseconds (e.g., 1000)callback (optional): A function to run after the fade-in is completeThe following example demonstrates the fadeIn() method with different parameters:
Try it yourself
The fadeOut() method gradually hides a visible element by reducing its opacity to 0, then sets display: none.
$(selector).fadeOut(speed, callback);
speed (optional): "slow", "fast", or milliseconds (e.g., 1000)callback (optional): Function to run after the fade-out is completeThe following example demonstrates the fadeOut() method with different parameters:
Try it yourself
The fadeToggle() method allows you to toggle between fadeIn() and fadeOut() — meaning it will:
All in one method!
$(selector).fadeToggle(speed, easing, callback);
speed (optional) – "slow", "fast", or milliseconds (e.g., 1000)easing (optional) – Animation easing ("swing" or "linear")callback (optional) – Function to run after toggle completesThe following example demonstrates the fadeToggle() method with different parameters:
Try it yourself
The fadeTo() method fades an element to a specified opacity (without hiding it completely like fadeOut()).
$(selector).fadeTo(speed, opacity, callback);
speed: "slow", "fast", or a number in milliseconds (e.g., 1000)opacity: A number between 0.0 (fully transparent) and 1.0 (fully opaque)callback: Optional function to run after the animation completesThe following example demonstrates the fadeTo() method :
Try it yourself