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


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


SoundCloud是一個在線音頻分發和共享網站,可以使用amp-soundcloud組件將音樂和播放列表嵌入AMP HTML頁麵,該組件可用於在您的網站中保存您喜歡的歌曲或SoundCloud播放列表。

SoundCloud鏈接:https://soundcloud.com/

所需腳本:導入amp-soundcloud組件

HTML



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

屬性:

  • data-playlistid:如果未指定data-trackid,則需要指定。這是SoundCloud中播放列表的ID。
  • data-trackid:如果未指定data-playlistid,則需要指定。這是SoundCloud中曲目的ID。
  • data-visual:如果設置為true,則設置全角視覺模式。
  • data-color:它設置了覆蓋默認值的特定顏色。顏色應以十六進製數指定。

例:

HTML

<!doctype html> 
<html ⚡> 
  
<head> 
    <meta charset="utf-8"> 
    <title>Google AMP amp-soundcloud</title> 
  
    <script async src= 
        "https://cdn.ampproject.org/v0.js"> 
    </script> 
      
    <!--Import the `amp-soundcloud` component.-->
    <script async custom-element="amp-soundcloud" 
src="https://cdn.ampproject.org/v0/amp-soundcloud-0.1.js"> 
    </script> 
      
    <link rel="canonical" href= 
"https://amp.dev/documentation/examples/components/amp-soundcloud/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> 
    <!--fixed-height layout-->
    <amp-soundcloud height="200" 
        layout="fixed-height" 
        data-trackid="89299804"> 
    </amp-soundcloud> 
  
    <!--data-color mentioned.-->
    <amp-soundcloud height="200" 
        layout="fixed-height" 
        data-trackid="89299804" 
        data-color="448AFF"> 
    </amp-soundcloud> 
      
    <!-- allows embedding Soundcloud playlist-->
    <amp-soundcloud height="350" 
        layout="fixed-height" 
        data-playlistid="331919427" 
        data-visual="true"> 
    </amp-soundcloud> 
</body> 
  
</html>

輸出:




相關用法


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