banner



How To Slide Up And Down Animation With Javascript

.slideDown( [elapsing ] [, consummate ] ) Returns: jQuery

Description: Display the matched elements with a sliding motion.

  • version added: 1.0 .slideDown( [duration ] [, complete ] )

    • elapsing (default: 400)

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

    • consummate

      A function to call once the animation is consummate, chosen in one case per matched chemical element.

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

    • options

      A map of boosted options to pass to the method.

      • duration (default: 400)

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

      • easing (default: swing)

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

      • queue (default: true)

        A Boolean indicating whether to identify the blitheness in the furnishings queue. If imitation, the animation will begin immediately. As of jQuery 1.vii, the queue selection can likewise accept a string, in which instance the animation is added to the queue represented by that cord. When a custom queue name is used the animation does not automatically starting time; you must telephone call .dequeue("queuename") to starting time it.

      • specialEasing

        An object containing one or more of the CSS properties divers by the properties argument and their respective easing functions. (version added: 1.4)

      • step

        A function to be called for each animated property of each animated chemical element. This function provides an opportunity to modify the Tween object to change the value of the belongings before it is ready.

      • progress

        A function to be called later on each step of the animation, simply one time per animated chemical element regardless of the number of blithe backdrop. (version added: 1.8)

      • complete

        A function that is chosen once the blitheness on an element is complete.

      • start

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

      • done

        A function to exist called when the animation on an chemical element completes (its Promise object is resolved). (version added: ane.8)

      • neglect

        A function to be called when the blitheness on an element fails to complete (its Promise object is rejected). (version added: 1.8)

      • always

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

  • version added: 1.4.iii .slideDown( [elapsing ] [, easing ] [, complete ] )

    • duration (default: 400)

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

    • easing (default: swing)

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

    • complete

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

The .slideDown() method animates the meridian of the matched elements. This causes lower parts of the page to slide down, making way for the revealed items.

Durations are given in milliseconds; higher values signal slower animations, non faster ones. The strings 'fast' and 'slow' tin exist 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 elapsing of 400 milliseconds is used.

We tin can animate any element, such equally a simple image:

one

2

iii

4

                              

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

With the chemical element initially hidden, we tin show it slowly:

ane

ii

iii

4

5

                              

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

$( "#volume" ).slideDown( "slow", function() {

Figure i - Illustration of the slideDown() effect

Easing

As of jQuery one.4.3, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points inside 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 apply of plug-ins, near notably the jQuery UI suite.

Callback Function

If supplied, the callback is fired once the blitheness is complete. This can be useful for stringing dissimilar animations together in sequence. The callback is not sent whatsoever arguments, but this is set up to the DOM chemical element being blithe. If multiple elements are animated, it is important to note that the callback is executed once per matched element, not once for the animation equally a whole.

Equally of jQuery one.6, the .promise() method can be used in conjunction with the deferred.done() method to execute a single callback for the blitheness as a whole when all matching elements take completed their animations ( See the case for .hope() ).

Additional Notes:

  • All jQuery effects, including .slideDown(), can be turned off globally past setting jQuery.fx.off = true, which effectively sets the elapsing to 0. For more information, see jQuery.fx.off.
  • If .slideDown() is called on an unordered list (<ul>) and its <li> elements have position (relative, absolute, or stock-still), the effect may non work properly in IE6 through at least IE9 unless the <ul> has "layout." To remedy the problem, add together the position: relative; and zoom: 1; CSS declarations to the ul.

Examples:

Animates all divs to slide down and bear witness themselves over 600 milliseconds.

i

two

3

four

5

6

7

8

ix

10

eleven

12

13

14

fifteen

16

17

18

19

twenty

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

                                

<title>slideDown demo</title>

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

$( document.body ).click( function () {

if ( $( "div" ).first().is( ":hidden" ) ) {

$( "div" ).slideDown( "tedious" );

Demo:

Animates all inputs to slide down, completing the animation within 1000 milliseconds. Once the animation is done, the input await is inverse especially if it is the heart input which gets the focus.

1

2

3

4

five

half dozen

7

8

9

x

11

12

13

xiv

15

16

17

eighteen

19

20

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

50

51

52

                                

<title>slideDown demo</championship>

edge: 2px outset blackness;

<script src="https://lawmaking.jquery.com/jquery-3.v.0.js"> </script>

<input type="text" class="centre">

$( "div" ).click( part() {

$( "input" ).slideDown( grand, function() {

.css( "border", "2px red inset" )

.css( "background", "yellow" )

$( "div" ).css( "visibility", "hidden" );

Demo:

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

Posted by: vogtrawn1970.blogspot.com

0 Response to "How To Slide Up And Down Animation With Javascript"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel