當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


CSS animation-direction用法及代碼示例


CSS中的animation-direction屬性用於定義動畫的方向。動畫的方向應為向前,向後或交替循環。

用法:

animation-direction:normal|reverse|alternate|alternate-reverse|
initial|inherit;

屬性值:下麵列出了animation-direction屬性:
normal:此動畫屬性將動畫向前播放。它是默認值。


  • 用法:
    animation-direction:normal; 
  • Example:
    <!DOCTYPE html>  
    <html>  
        <head>  
            <title> 
                CSS | animation-direction Property 
            </title> 
            <style>  
                body { 
                    text-align:center; 
                } 
                h1 { 
                    color:green; 
                } 
                h3 {  
                    width:100%;  
                    animation-name:text;  
                    animation-duration:2s;  
                    animation-iteration-count:infinite;  
                }  
                #one {  
                    animation-direction:normal;  
                }  
                @keyframes text {  
                    from {  
                        margin-left:60%;  
                    }  
                    to {  
                        margin-left:0%;  
                    }  
                }  
            </style>  
        </head>  
        <body>  
            <h1>GeeksforGeeks</h1>  
            <h2>animation-direction property</h2>  
            <h3 id="one">This text is normal.</h3>  
        </body>  
    </html>                                     
  • Output:

reverse:此動畫屬性以相反的方向播放動畫。

  • 用法:
    animation-direction:reverse;
  • 例:
    <!DOCTYPE html>  
    <html>  
        <head>  
            <title> 
                CSS | animation-direction Property 
            </title> 
            <style>  
                body { 
                    text-align:center; 
                } 
                h1 { 
                    color:green; 
                } 
                h3 {  
                    width:100%;  
                    animation-name:text;  
                    animation-duration:2s;  
                    animation-iteration-count:infinite;  
                }  
                #one {  
                    animation-direction:reverse;  
                }  
                @keyframes text {  
                    from {  
                        margin-left:60%;  
                    }  
                    to {  
                        margin-left:0%;  
                    }  
                }  
            </style>  
        </head>  
        <body>  
            <h1>GeeksforGeeks</h1>  
            <h2>animation-direction property</h2>  
            <h3 id="one">This text is reverse.</h3>  
        </body>  
    </html>                                     
  • 輸出:

交替:此動畫屬性先播放動畫,然後播放動畫。

  • 用法:
    animation-direction:alternate; 
  • 例:
    <!DOCTYPE html>  
    <html>  
        <head>  
            <title> 
                CSS | animation-direction Property 
            </title> 
            <style>  
                body { 
                    text-align:center; 
                } 
                h1 { 
                    color:green; 
                } 
                h3 {  
                    width:100%;  
                    animation-name:text;  
                    animation-duration:2s;  
                    animation-iteration-count:infinite;  
                }  
                #one {  
                    animation-direction:alternate;  
                }  
                @keyframes text {  
                    from {  
                        margin-left:60%;  
                    }  
                    to {  
                        margin-left:0%;  
                    }  
                }  
            </style>  
        </head>  
        <body>  
            <h1>GeeksforGeeks</h1>  
            <h2>animation-direction property</h2>  
            <h3 id="one">This text is alternate.</h3>  
        </body>  
    </html>                                     
  • 輸出:

alternate-reverse:此動畫屬性首先向後播放動畫,然後向前播放。

  • 用法:
    animation-direction:alternate-reverse;
  • 例:
    <!DOCTYPE html>  
    <html>  
        <head>  
            <title> 
                CSS | animation-direction Property 
            </title> 
            <style>  
                body { 
                    text-align:center; 
                } 
                h1 { 
                    color:green; 
                } 
                h3 {  
                    width:100%;  
                    animation-name:text;  
                    animation-duration:2s;  
                    animation-iteration-count:infinite;  
                }  
                #one {  
                    animation-direction:alternate-reverse; 
                }  
                @keyframes text {  
                    from {  
                        margin-left:60%;  
                    }  
                    to {  
                        margin-left:0%;  
                    }  
                }  
            </style>  
        </head>  
        <body>  
            <h1>GeeksforGeeks</h1>  
            <h2>animation-direction property</h2>  
            <h3 id="one">This text is alternate-reverse.</h3>  
        </body>  
    </html>                                     
  • 輸出:

initial:此屬性用於將animation屬性設置為其默認值。

繼承:此屬性用於從其父元素繼承animation屬性。

支持的瀏覽器:下麵列出了animation-direction屬性支持的瀏覽器:

  • 穀歌瀏覽器43.0
  • Internet Explorer 10.0
  • Firefox 16.0
  • Opera 30.0
  • Safari 9.0


相關用法


注:本文由純淨天空篩選整理自vt_m大神的英文原創作品 CSS | animation-direction Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。