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


Google AMP amp-lightbox-gallery用法及代碼示例


amp-lightbox-gallery組件用於為其他放大器組件(如amp-carousel,amp-img)提供燈箱體驗。目前,amp-lightbox-gallery僅支持圖像。

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

HTML

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

屬性:



  • lightbox:我們使用此屬性為圖像添加燈箱效果。
  • src:指定要嵌入的圖像的URL或路徑。
  • layout:指定圖像的布局,例如反應靈敏。

例:

HTML

<!doctype html> 
<html ⚡> 
  
<head> 
    <meta charset="utf-8"> 
    <link rel="canonical" href= 
"https://amp.dev/documentation/examples/components/amp-lightbox-gallery/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> 
  
    <script async custom-element="amp-carousel"
src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"> 
    </script> 
  
    <title>Google AMP amp-lightbox-gallery</title> 
  
    <!-- Import the amp-lightbox-gallery  
        component in the header.  -->
    <script async custom-element="amp-lightbox-gallery"
src="https://cdn.ampproject.org/v0/amp-lightbox-gallery-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> 
        :root { 
            --color-primary:#005AF0; 
            --color-text-light:#fff; 
            --space-1:.5rem; 
            --space-2:1rem; 
        } 
    </style> 
</head> 
  
<body> 
    <div> 
        <amp-img lightbox src= 
"https://pbs.twimg.com/profile_images/1304985167476523008/QNHrwL2q_400x400.jpg"
            width="300" height="200"
            layout="responsive"> 
        </amp-img> 
  
        <p class="paragraph"> 
            welcome to geeksforgeeks 
        </p> 
  
          
        <amp-img lightbox 
            src= 
"https://media.geeksforgeeks.org/wp-content/cdn-uploads/20200817185016/gfg_complete_logo_2x-min.png"
            width="300" height="200"
            layout="responsive"> 
        </amp-img> 
  
        <p class="paragraph"> 
            GeeksforGeeks A Computer Science  
            portal for geeks. 
        </p> 
  
    </div> 
</body> 
  
</html>

輸出:

代碼輸出

單擊圖像可得到以下視圖

在圖像上單擊

單擊左上方的圖庫選項可提供以下視圖

圖庫視圖




相關用法


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