banner



How To Animate A Picture Fading Away In Jquery

.fadeOut( [elapsing ] [, complete ] ) Returns: jQuery

Description: Hide the matched elements by fading them to transparent.

  • version added: 1.0 .fadeOut( [duration ] [, consummate ] )

    • elapsing (default: 400)

      A string or number determining how long the blitheness volition run.

    • complete

      A function to telephone call once the animation is consummate, called once per matched element.

  • version added: i.0 .fadeOut( options )

    • options

      A map of additional options to pass to the method.

      • duration (default: 400)

        A string or number determining how long the animation will run.

      • easing (default: swing)

        A string indicating which easing office to use for the transition.

      • queue (default: truthful)

        A Boolean indicating whether to place the animation in the effects queue. If false, the animation will begin immediately. As of jQuery 1.7, the queue option tin also take a string, in which case the animation is added to the queue represented by that cord. When a custom queue name is used the animation does not automatically start; yous must call .dequeue("queuename") to commencement it.

      • specialEasing

        An object containing one or more of the CSS properties divers by the backdrop argument and their corresponding easing functions. (version added: ane.4)

      • step

        A function to be chosen for each animated property of each animated chemical element. This function provides an opportunity to modify the Tween object to alter the value of the belongings earlier information technology is set.

      • progress

        A function to be called afterward each step of the animation, only once per animated element regardless of the number of animated backdrop. (version added: 1.8)

      • consummate

        A function that is called once the animation on an element is complete.

      • commencement

        A role to telephone call when the animation on an element begins. (version added: i.eight)

      • done

        A function to be chosen when the animation on an element completes (its Promise object is resolved). (version added: i.viii)

      • fail

        A role to be chosen when the blitheness on an element fails to complete (its Promise object is rejected). (version added: 1.eight)

      • e'er

        A function to be called when the blitheness on an chemical element completes or stops without completing (its Promise object is either resolved or rejected). (version added: 1.8)

  • version added: 1.iv.3 .fadeOut( [duration ] [, easing ] [, consummate ] )

    • duration (default: 400)

      A string or number determining how long the animation will run.

    • easing (default: swing)

      A cord indicating which easing function to use for the transition.

    • complete

      A function to call once the animation is complete, called one time per matched chemical element.

The .fadeOut() method animates the opacity of the matched elements. Once the opacity reaches 0, the brandish fashion property is set to none, and so the chemical element no longer affects the layout of the page.

Durations are given in milliseconds; college values indicate slower animations, non faster ones. The strings 'fast' and 'slow' can be supplied to indicate durations of 200 and 600 milliseconds, respectively. If any other string is supplied, or if the duration parameter is omitted, the default duration of 400 milliseconds is used.

We tin animate whatever chemical element, such as a simple image:

1

2

3

four

                              

<img id="book" src="volume.png" alt="" width="100" height="123">

With the chemical element initially shown, we can hide it slowly:

1

2

3

4

5

                              

$( "#clickme" ).click( function() {

$( "#book" ).fadeOut( "ho-hum", function() {

Figure 1 - Analogy of the fadeOut() effect

Annotation: To avoid unnecessary DOM manipulation, .fadeOut() will non hibernate an element that is already considered hidden. For information on which elements jQuery considers hidden, run into :hidden Selector.

Easing

As of jQuery one.four.three, an optional cord naming an easing role may exist used. Easing functions specify the speed at which the animation progresses at unlike points within the blitheness. The only easing implementations in the jQuery library are the default, called swing, and one that progresses at a constant pace, called linear. More easing functions are bachelor with the use of plug-ins, most notably the jQuery UI suite.

Callback Function

If supplied, the callback is fired once the animation is complete. This can exist useful for stringing different animations together in sequence. The callback is not sent any arguments, only this is set up to the DOM element being animated. If multiple elements are animated, it is important to note that the callback is executed in one case per matched element, not once for the animation every bit a whole.

As of jQuery one.half-dozen, the .promise() method tin can be used in conjunction with the deferred.done() method to execute a single callback for the animation as a whole when all matching elements have completed their animations ( See the example for .promise() ).

Additional Notes:

  • All jQuery furnishings, including .fadeOut(), can exist turned off globally by setting jQuery.fx.off = true, which effectively sets the elapsing to 0. For more than information, meet jQuery.fx.off.

Examples:

Animates all paragraphs to fade out, completing the blitheness inside 600 milliseconds.

1

2

iii

four

five

6

7

viii

9

10

11

12

13

14

fifteen

16

17

18

19

20

21

22

23

24

25

26

27

28

                                

<title>fadeOut demo</title>

<script src="https://code.jquery.com/jquery-3.5.0.js"> </script>

If you click on this paragraph

yous'll run into it just fade abroad.

$( "p" ).click( function() {

$( "p" ).fadeOut( "slow" );

Demo:

Fades out spans in one section that you click on.

1

two

three

iv

v

vi

seven

8

9

10

11

12

13

fourteen

15

sixteen

17

xviii

xix

xx

21

22

23

24

25

26

27

28

29

xxx

31

32

33

34

35

36

37

38

39

twoscore

41

42

43

44

45

                                

<title>fadeOut demo</title>

<script src="https://code.jquery.com/jquery-iii.5.0.js"> </script>

<h3>Notice the modifiers - <div> </div> </h3>

If y'all <bridge>really</span> want to get exterior

<bridge>in the common cold</span> then make sure to habiliment

your <span>warm</span> jacket given to y'all by

your <span>favorite</span> teacher.

$( "span" ).click( function() {

$( this ).fadeOut( 1000, role() {

$( "div" ).text( "'" + $( this ).text() + "' has faded!" );

$( "span" ).hover( function() {

$( this ).addClass( "hilite" );

$( this ).removeClass( "hilite" );

Demo:

Fades out 2 divs, one with a "linear" easing and one with the default, "swing," easing.

1

2

3

four

5

6

7

eight

9

ten

11

12

13

14

15

16

17

eighteen

19

xx

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

                                

<title>fadeOut demo</championship>

<script src="https://code.jquery.com/jquery-3.5.0.js"> </script>

<push button id="btn1">fade out</button>

<push id="btn2">show</button>

<div id="box1" grade="box">linear</div>

<div id="box2" class="box">swing</div>

$( "#btn1" ).click( function() {

$( "<div>" ).text( this.id ).appendTo( "#log" );

$( "#box1" ).fadeOut( 1600, "linear", complete );

$( "#box2" ).fadeOut( 1600, complete );

$( "#btn2" ).click( function() {

Demo:

Source: https://api.jquery.com/fadeout/

Posted by: byerssuman1965.blogspot.com

0 Response to "How To Animate A Picture Fading Away In Jquery"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel