amp-lightbox
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>
You can combine the lightbox component with amp-bind
.
<script async custom-element="amp-bind" src="https://cdn.ampproject.org/v0/amp-bind-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.
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.
Hello World!
<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>
<button on="tap:my-lightbox">
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.
Combination with amp-bind
amp-lightbox
can be opened as a result of amp-bind
evaluations by binding a boolean value to the open
attribute. Note that we're also listening to the lightboxClose
event to reset the state of the variable.
Hello World!
<amp-lightbox id="my-bindable-lightbox" [open]="showLightbox" layout="nodisplay" on="lightboxClose:AMP.setState({showLightbox: false})">
<div class="lightbox" role="button" tabindex="0" on="tap:my-bindable-lightbox.close">
<h1>Hello World!</h1>
</div>
</amp-lightbox>
<button on="tap:AMP.setState({showLightbox: true})">
Open lightbox
</button>
이 페이지의 설명만으로 궁금한 점이 모두 해결되지 않는다면 다른 AMP 사용자에게 문의하여 구체적인 활용 사례를 논의해 보세요.
Stack Overflow로 이동 설명이 부족한 기능을 발견하셨나요?AMP 프로젝트는 여러분의 참여와 기여를 적극 환영합니다! 오픈 소스 커뮤니티를 통해 지속적으로 활동해 주셔도 좋지만 관심 있는 주제에 한 번만 기여하셔도 큰 도움이 됩니다.
GitHub에서 샘플 수정하기-
Written by @sebastianbenz