Getting Started with jquery (6) Fade effect

Source: Internet
Author: User

JQuery provides the following ways to achieve the fade effect shown:

FadeIn ()

Fadeout ()

Fadetoggle ()

Fadeto ()

FadeIn () method

FadeIn () implements the fade effect with the following basic syntax:

$ (selector). FadeIn (Speed,callback);

Optional parameter speed gives the time to fade in, you can use "slow", "fast", or a value (microseconds)

The Second optional parameter is the callback function, which is invoked after the Fadein () method finishes.

$ ("button"). Click (function () {     
  $ ("#center1"). FadeIn ();     
  $ ("#center2"). FadeIn ("slow");     
  $ ("#center3"). FadeIn (3000);     

Fadeout () method

Fadeout () implements the fade effect, its basic syntax is as follows:

$ (selector). fadeout (Speed,callback);

Optional parameter speed gives the time to fade in, you can use "slow", "fast", or a value (microseconds)

The Second optional parameter is the callback function, which is invoked after the Fadein () method finishes.

$ ("button"). Click (function () {     
  $ ("#center1"). fadeout ();     
  $ ("#center2"). Fadeout ("slow");     
  $ ("#center3"). Fadeout (3000);     

Fadetoggle () method

Fadetoggle () alternately Fadein () and fadeout (), if the element is faded, fadetoggle () fades into the element, and Fadetoggle fades out if the element was previously in the fade.

The basic syntax is as follows:

$ (selector). Fadetoggle (Speed,callback);

Optional parameter speed gives the time to fade in, you can use "slow", "fast", or a value (microseconds)

The Second optional parameter is the callback function, which is invoked after the Fadein () method finishes.

In the following example, after clicking the button, you can alternately fade in three rectangles.

<! DOCTYPE html>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.