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


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

GitHub是非常受歡迎的開發人員,它在web-pages中添加了要點,已經變得非常流行,使用amp-gist組件在AMP HTML中添加了要點。

必需的腳本:將amp-gist組件導入標頭。

HTML

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

屬性:



  • data-gistid:要嵌入到頁麵中的要點的ID。
  • height:要點的高度。
  • data-file:僅顯示要點的一個文件。

例:

HTML

<!doctype html> 
<html ⚡> 
  
<head> 
    <meta charset="utf-8"> 
  
    <title>Google AMP amp-gist</title> 
      
    <link rel="canonical" href= 
"https://amp.dev/documentation/examples/components/amp-gist/index.html"> 
      
    <meta name="viewport" content= 
"width=device-width,minimum-scale=1,initial-scale=1"> 
      
    <script async src= 
        "https://cdn.ampproject.org/v0.js"> 
    </script> 
      
    <!-- Import the amp-gist component -->
    <script async custom-element="amp-gist" 
src="https://cdn.ampproject.org/v0/amp-gist-0.1.js"> 
    </script> 
  
    <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> 
        amp-gist { 
            margin:1rem; 
        } 
    </style> 
  
</head> 
  
<body> 
  
    <!-- Embed an entire gist. -->
    <amp-gist data-gistid= 
        "b9bb35bc68df68259af94430f012425f" 
        layout="fixed-height" height="241"> 
    </amp-gist> 
  
    <!-- Embed one file out of a gist  
        using the `data-file` attribute.  
    The `data-file` attribute is optional. -->
    <amp-gist data-gistid= 
        "a19e811dcd7df10c4da0931641538497" 
        data-file="hi.c" layout="fixed-height" 
        height="197"> 
    </amp-gist> 
</body> 
  
</html>

輸出:




相關用法


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