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


Google AMP amp-anim用法及代碼示例

如果要在AMP網頁上嵌入動畫,則可以使用此標記。它可以幫助開發人員將動畫,gif,webp等嵌入到您的Web平台中。這確實是一個非常有用的標記,因為在您的網站上製作動畫確實使其變得俗氣且good-looking。

設置:

要在AMP網頁中使用amp-anim,您必須導入此腳本。

HTML



<script async custom-element="amp-anim" src= 
    "https://cdn.ampproject.org/v0/amp-anim-0.1.js"> 
</script>

在大多數方麵,它類似於amp-img。

例:

HTML

<!doctype html> 
<html amp> 
  
<head> 
    <meta charset="utf-8"> 
  
    <title>Google AMP amp-anim</title> 
      
    <script async src= 
        "https://cdn.ampproject.org/v0.js"> 
    </script> 
      
    <script async custom-element="amp-anim" 
src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"> 
    </script> 
      
    <meta name="viewport" content= 
"width=device-width,minimum-scale=1,initial-scale=1"> 
      
    <link rel="canonical" href= 
"https://amp.dev/documentation/examples/components/amp-anim/index.html"> 
      
    <style amp-boilerplate> 
        body { 
            -webkit-animation:-amp-start 8s  
                steps(1, end) 0s 1 normal both; 
  
            -moz-animation:-amp-start 8s  
                steps(1, end) 0s 1 normal both; 
  
            -ms-animation:-amp-start 8s  
                steps(1, end) 0s 1 normal both; 
  
            animation:-amp-start 8s  
                steps(1, end) 0s 1 normal both; 
        } 
  
        @-webkit-keyframes -amp-start { 
            from { 
                visibility:hidden 
            } 
  
            to { 
                visibility:visible 
            } 
        } 
  
        @-moz-keyframes -amp-start { 
            from { 
                visibility:hidden 
            } 
  
            to { 
                visibility:visible 
            } 
        } 
  
        @-ms-keyframes -amp-start { 
            from { 
                visibility:hidden 
            } 
  
            to { 
                visibility:visible 
            } 
        } 
  
        @-o-keyframes -amp-start { 
            from { 
                visibility:hidden 
            } 
  
            to { 
                visibility:visible 
            } 
        } 
  
        @keyframes -amp-start { 
            from { 
                visibility:hidden 
            } 
  
            to { 
                visibility:visible 
            } 
        } 
    </style> 
  
    <noscript> 
        <style amp-boilerplate> 
            body { 
                -webkit-animation:none; 
                -moz-animation:none; 
                -ms-animation:none; 
                animation:none 
            } 
        </style> 
    </noscript> 
  
    <style amp-custom> 
        h1 { 
            color:green; 
            text-align:center; 
        } 
    </style> 
</head> 
  
<body> 
    <h1> 
        Geeks For Geeks 
    </h1> 
      
    <amp-anim height="300" src= 
"https://media.giphy.com/media/xULW8rv9NSbHaEe9Ak/giphy.gif"
        alt="an animation"
        attribution="GeeksForGeeks"> 
    </amp-anim> 
</body> 
  
</html>

輸出:




相關用法


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