fadeTo() method in jQuery

fadeTo() in jQuery

fadeTo() method is used to change the opacity of the specified elements.

When using this method the elements opacity or transparency will be changed.

Syntax

$(selector).fadeTo(duration, opacity[, easing][, complete])

  • duration
    • Default value is 400.
    • number - Integer values are given in milliseconds.
    • slow - It specifies 600 milliseconds.
    • fast - It specifies 200 milliseconds.
  • opacity - It indicate the target opacity, its value is 0 to 1.
  • easing - It is optional, it specifies speed at which the animation progresses.It can have two values.
    • swing - It is a default value, animation progresses irregular way.
    • linear - it specifies animation progresses at a constant pace.
  • complete - It indicate a function, and it will be executed after the element animation complete.

Example 1 - Fadeto 0.1 opacity within 100ms

Try Yourself

Example 2 - fadeTo() with complete function

Try Yourself

Example 3 - calling complete function using function name

Try Yourself

Example 4 - fadeTo() using easing(linear) value

Try Yourself