Как добавить эффект лайтбокса в amp-carousel в Google AMP?
Опубликовано: 12 Апреля, 2022
Amp-carousel используется для создания карусели изображений на HTML-странице AMP. В AMP HTML также можно добавить эффект лайтбокса к amp-carousel с помощью amp-lightbox-gallery, учитывая, что amp-carousel содержит только изображения.
Required Script: Importing amp-carousel component into the header.
HTML
< script async custom-element = "amp-carousel" </ script > |
Импорт компонента amp-lightbox-gallery в заголовок
Example:
HTML
<!doctype html> < html > < head > < meta charset = "utf-8" > < link rel = "canonical" href = < meta name = "viewport" content = "width=device-width,minimum-scale=1,initial-scale=1" > < script async src = </ script > < script async custom-element = "amp-carousel" </ script > < title >Google AMP amp-lightbox-gallery</ title > <!-- Import the amp-lightbox-gallery component in the header. --> < script async custom-element = "amp-lightbox-gallery" </ 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 > < amp-carousel lightbox width = "1600" height = "1300" layout = "responsive" type = "slides" > < amp-img src = width = "200" height = "100" > </ amp-img > < amp-img src = "https://media.geeksforgeeks.org/wp-content/cdn-uploads/20200817185016/gfg_complete_logo_2x-min.png" width = "200" height = "100" > </ amp-img > < amp-img src = width = "200" height = "100" > </ amp-img > </ amp-carousel > </ body > </ html > |
Выход:
Когда мы щелкнули по изображению, мы увидим следующее представление
когда мы нажали на опцию верхней левой галереи, мы увидим следующий вид