Skip to content

Commit

Permalink
added support for video poster
Browse files Browse the repository at this point in the history
  • Loading branch information
ApoorvSaxena committed Oct 30, 2019
1 parent 94b2e3b commit cf87dee
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 5 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -211,6 +211,15 @@ Create _a broken_ picture element structure.

When _lozad_ loads this picture element, it will fix it.

## Example with video

```html
<video data-poster="images/backgrounds/video-poster.jpeg">
<source data-src="video/mov_bbb.mp4" type="video/mp4">
<source data-src="video/mov_bbb.ogg" type="video/ogg">
</video>
```

## Example with iframe

```html
Expand Down
Binary file added demo/images/backgrounds/video-poster.jpeg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion demo/index.html
Expand Up @@ -258,7 +258,7 @@ <h1>&lt;video> example</h1>
<div id="video">
<article class="frame">
<div class="video-example video-example-2">
<video width="560" height="315" controls loop muted class="lozad-picture">
<video width="560" height="315" controls loop muted class="lozad-picture" data-poster="images/backgrounds/video-poster.jpeg">
<source data-src="video/mov_bbb.mp4" type="video/mp4">
<source data-src="video/mov_bbb.ogg" type="video/ogg">
</video>
Expand Down
6 changes: 5 additions & 1 deletion dist/lozad.es.js
@@ -1,4 +1,4 @@
/*! lozad.js - v1.14.0 - 2019-10-19
/*! lozad.js - v1.14.0 - 2019-10-30
* https://github.com/ApoorvSaxena/lozad.js
* Copyright (c) 2019 Apoorv Saxena; Licensed MIT */

Expand Down Expand Up @@ -42,6 +42,10 @@ const defaultConfig = {
}
}

if (element.getAttribute('data-poster')){
element.poster = element.getAttribute('data-poster');
}

if (element.getAttribute('data-src')) {
element.src = element.getAttribute('data-src');
}
Expand Down
6 changes: 5 additions & 1 deletion dist/lozad.js
@@ -1,4 +1,4 @@
/*! lozad.js - v1.14.0 - 2019-10-19
/*! lozad.js - v1.14.0 - 2019-10-30
* https://github.com/ApoorvSaxena/lozad.js
* Copyright (c) 2019 Apoorv Saxena; Licensed MIT */

Expand Down Expand Up @@ -48,6 +48,10 @@
}
}

if (element.getAttribute('data-poster')) {
element.poster = element.getAttribute('data-poster');
}

if (element.getAttribute('data-src')) {
element.src = element.getAttribute('data-src');
}
Expand Down
4 changes: 2 additions & 2 deletions dist/lozad.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/lozad.js
Expand Up @@ -37,6 +37,10 @@ const defaultConfig = {
}
}

if (element.getAttribute('data-poster')){
element.poster = element.getAttribute('data-poster')
}

if (element.getAttribute('data-src')) {
element.src = element.getAttribute('data-src')
}
Expand Down

0 comments on commit cf87dee

Please sign in to comment.