Video / Embed Example Code
Like the the image gallery example, the code below uses data
attributes on link elements to pass data to BiggerPicture when a link
is clicked. Instead of a gallery, we just open them on their own by
passing the individual node.
For native video and audio, you must provide sources
--
an array of objects indicating a
src
and
type
(mime). A string may be used if it is JSON parsable. Each object will
create a <source> element, and all key-value pairs in the object
will be added as attributes.
Videos have a tracks
option allowing you to add captions,
which you can see in use below.
Note: Width / height defaults to 1920 / 1080, so those attributes
aren't necessary, but are left in for clarity.
<a
href="example.mp4"
data-width="1920"
data-height="1080"
data-thumb="thumb.jpg"
data-sources='[{"src": "example.webm", "type": "video/webm"}, {"src": "example.mp4", "type": "video/mp4"}]'
data-tracks='[{"label": "English", "kind": "subtitles", "srclang": "en", "src": "en.vtt", "default": "true"}, {"label": "Español", "kind": "subtitles", "srclang": "es", "src": "es.vtt"}]'
>
<img
src="thumb.jpg"
alt="video description"
/>
</a>
<a
href="https://www.youtube.com/watch?v=286jXjwdst0"
data-width="1920"
data-height="1012"
data-thumb="images/uebok.jpg"
data-iframe="https://www.youtube.com/embed/286jXjwdst0?autoplay=1&playsinline=1"
>
<img
src="images/uebok.jpg"
alt="Uebok youtube embed"
/>
</a>
let bp = BiggerPicture({
target: document.body
});
let links = document.querySelectorAll("a");
for (let link of links) {
link.addEventListener("click", openBiggerPicture);
}
function openBiggerPicture(e) {
e.preventDefault();
bp.open({
items: e.currentTarget,
el: e.currentTarget
});
}