amp-lightbox

Edit on Github
Open in Playground

Introduction

The amp-lightbox component allows for a “lightbox” or similar experience - where upon user interaction a component expands to fill the viewport, until it is closed again by the user.

Setup

Import the amp-lightbox component in the header

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

Basic Usage

The amp-lightbox component defines the child elements that will be displayed in a full-viewport overlay. To close the lightbox via click or tap use the on attribute on one or more elements inside the lightbox. In this example the user can click anywhere in the lightbox to close it.

Example

<amp-lightbox id="my-lightbox"
  layout="nodisplay">
  <div class="lightbox"
    on="tap:my-lightbox.close"
    role="button"
    tabindex="0">
    <h1>Hello World!</h1>
  </div>
</amp-lightbox>

The lighbox is shown when the user taps or clicks on an element with on attribute that targets the id of an amp-lightbox element.

Example

<button class="ampstart-btn caps m2"
  on="tap:my-lightbox"
  role="button"
  tabindex="0">
  Open lightbox
</button>

For showing images in a lightbox, AMP also features the amp-image-lightbox component, which doesn't need the image to specified twice.