当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


HTML Style transitionDelay用法及代码示例


HTML DOM中的transitionDelay属性用于指定开始执行过渡的时间,以秒或毫秒为单位。延迟是指开始过渡效果之前要等待的时间。

用法:

  • 它返回transitionDelay属性。
    object.style.transitionDelay
  • 设置transitionDelay属性。
    object.style.transitionDelay = "time|initial|inherit"

属性值:


  • time:它指定开始过渡动画的时间长度(以秒或毫秒为单位)。
    用法:
    object.style.transitionDelay = "time";

    例:

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

    输出:
    在单击按钮之前:

    单击按钮后:转换延迟:3秒

  • initial:它将transitionDelay属性设置为其默认值。
    用法:
    object.style.transitionDelay = "initial";

    例:

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

    输出:
    在单击按钮之前:

    单击按钮后:转换延迟:0秒。因为默认的转换延迟是0秒。

  • inherit:transitionDelay属性是从其父级继承的。
    用法:
    object.style.transitionDelay = "inherit";

    范例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>                    

    输出:
    在单击按钮之前:

    单击按钮后:转换延迟:2秒。因为父类包含2秒的转换延迟。

返回值:它返回一个表示元素的transitionDelay属性的字符串值。

支持的浏览器:下面列出了DOM transitionDelay属性支持的浏览器:

  • 谷歌浏览器26.0
  • Internet Explorer 10.0
  • Firefox 16.0
  • Safari 6.1、3.1 WebkitTransitionDelay
  • Opera 12.1


相关用法


注:本文由纯净天空筛选整理自riarawal99大神的英文原创作品 HTML | DOM Style transitionDelay Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。