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


Google AMP amp-facebook-like用法及代碼示例


簡介:網頁中真正受歡迎的函數就像來自社交媒體平台的按鈕。 amp-facebook-like用於將類似Facebook的按鈕嵌入到AMP HTML頁麵。在這裏,當嵌入了“ Facebook讚”按鈕時,您無需打開Facebook即可喜歡該帖子。

必需的腳本:添加以下包含源的腳本以導入amp-facebook-like組件。

HTML

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

屬性:

  1. data-href:要頂頁麵的URL。
  2. data-action:要在按鈕上顯示的字符串。默認值為“Like”。
  3. data-colorscheme:應在按鈕外部使用的配色方案。默認情況下,它是亮的,也可以保持黑暗。
  4. data-size:用於更改按鈕的大小。默認情況下,它很小,也可以設置為大。
  5. data-layout:它用於更改按鈕的布局。有四種可用的布局,它們是:
    • 標準(默認)
    • button
    • button_count
    • box_count

例:

HTML

<!doctype html> 
<html amp> 
  
<head> 
    <meta charset="utf-8"> 
    <title>amp-facebook-like</title> 
    <script async src= 
        "https://cdn.ampproject.org/v0.js"> 
    </script> 
  
    <!-- Import the `amp-facebook-like`  
        component to add a like button-->
    <script async custom-element= 
            "amp-facebook-like" src= 
"https://cdn.ampproject.org/v0/amp-facebook-like-0.1.js"> 
    </script> 
  
    <link rel="canonical" href= 
"https://amp.dev/documentation/examples/components/amp-facebook-like/index.html"> 
    <meta name="viewport" content= 
"width=device-width,minimum-scale=1,initial-scale=1"> 
    <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> 
</head> 
  
<body> 
    <amp-facebook-like width="100" height="30"
        layout="fixed" data-layout="button_count"
        data-href= 
"https://www.facebook.com/testesmegadivertidos/"> 
    </amp-facebook-like> 
</body> 
  
</html>

輸出




相關用法


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