HTML | DOM Style transitionDelay Property

The transitionDelay property in HTML DOM is used to specify the time in seconds or milliseconds when execution of transition starts. The delay refers to the time, which to be waited before starting the transition effect.

Syntax:

  • It returns the transitionDelay property.
    object.style.transitionDelay
  • It sets the transitionDelay property.
    object.style.transitionDelay = "time|initial|inherit"

Property Values:



  • time: It specifies the length of time (in seconds or milliseconds) to start transition animation.
    Syntax:

    object.style.transitionDelay = "time";

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            HTML DOM Style transitionDelay Property
        </title>
          
        <!-- CSS property for transition animation -->
        <style
            #GFG {
                border: 1px solid black;
                background-color: white;
                width: 250px;
                height: 200px;
                overflow: auto;
                -webkit-transition: all 3s;
                transition: all 3s;
                text-align:center;
            }
              
            #GFG:hover {
                background-color: green;
                width: 300px;
                height: 100px;
                 
                text-align:center;
            }
        </style>
    </head>
      
    <body>
      
        <button onclick="myGeeks()">
            Click Here!
        </button>
          
        <br><br>
          
        <div id = "GFG">
            <h1>GeeksforGeeks</h1>
        </div>
          
        <!-- script for transition delay -->
        <script>
            function myGeeks() {
                document.getElementById("GFG").style.WebkitTransitionDelay
                        = "3s"; 
                          
                document.getElementById("GFG").style.transitionDelay
                        = "3s";     
            }
        </script>
    </body>
      
    </html>                    

    chevron_right

    
    

    Output:
    Before click on the Button:

    After click on the Button: Transition delay : 3 seconds

  • initial: It sets the transitionDelay property to its default value.
    Syntax:

    object.style.transitionDelay = "initial";

    Example:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            HTML DOM Style transitionDelay Property
        </title>
          
        <!-- CSS property for transition animation -->
        <style
            #GFG {
                border: 1px solid black;
                background-color: white;
                width: 250px;
                height: 200px;
                overflow: auto;
                -webkit-transition: all 3s;
                transition: all 3s;
                text-align:center;
            }
              
            #GFG:hover {
                background-color: green;
                width: 300px;
                height: 100px;
                 
                text-align:center;
            }
        </style>
    </head>
      
    <body>
      
        <button onclick="myGeeks()">
            Click Here!
        </button>
          
        <br><br>
          
        <div id = "GFG">
            <h1>GeeksforGeeks</h1>
        </div>
          
        <!-- script for transition delay -->
        <script>
            function myGeeks() {
                document.getElementById("GFG").style.WebkitTransitionDelay
                        = "initial"; 
                          
                document.getElementById("GFG").style.transitionDelay
                        = "initial";     
            }
        </script>
    </body>
      
    </html>                            

    chevron_right

    
    

    Output:
    Before click on the Button:

    After click on the Button: Transition delay : 0 seconds. Because default transition delay is 0 seconds.

  • inherit: The transitionDelay property is inherited from its parent.
    Syntax:

    object.style.transitionDelay = "inherit";

    Example 3:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <!DOCTYPE html>
    <html>
          
    <head>
        <title>
            HTML DOM Style transitionDelay Property
        </title>
          
        <!-- CSS property for transition animation -->
        <style
            #GFG {
                border: 1px solid black;
                background-color: white;
                width: 250px;
                height: 200px;
                overflow: auto;
                -webkit-transition: all 3s;
                transition: all 3s;
                text-align:center;
            }
              
            #main {
                transition-delay:2s;
                -webkit-transition-delay:2s
            }
            #GFG:hover {
                background-color: green;
                width: 300px;
                height: 100px;
                 
                text-align:center;
            }
        </style>
    </head>
      
    <body>
      
        <button onclick="myGeeks()">
            Click Here!
        </button>
          
        <br><br>
          
        <div id = "main">
            <div id = "GFG">
                <h1>GeeksforGeeks</h1>
            </div>
        </div>
          
        <!-- script for transition delay -->
        <script>
            function myGeeks() {
                document.getElementById("GFG").style.WebkitTransitionDelay
                        = "inherit"; 
                          
                document.getElementById("GFG").style.transitionDelay
                        = "inherit";     
            }
        </script>
    </body>
      
    </html>                    

    chevron_right

    
    

    Output:
    Before click on the Button:

    After click on the Button: Transition delay : 2 seconds. Because the parent class contains transition delay 2 seconds.

Return Value: It returns a string value which represents the transitionDelay property of an element.

Supported Browsers: The browser supported by DOM transitionDelay property are listed below:

  • Google Chrome 26.0
  • Internet Explorer 10.0
  • Firefox 16.0
  • Safari 6.1, 3.1 WebkitTransitionDelay
  • Opera 12.1


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.