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


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。