Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

HTML | DOM Style transitionDelay Property

  • Last Updated : 28 Jan, 2019

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:

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.

  • 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:




    <!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>                    

    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:




    <!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>                            

    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:




    <!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>                    

    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
Recommended Articles
Page :