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


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