Skip to content

Commit bc258ab

Browse files
committed
✨ add support for videos #41
1 parent b6a994f commit bc258ab

File tree

8 files changed

+73
-31
lines changed

8 files changed

+73
-31
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Simply copy/paste the below snippet just before your closing `</body>` tag:
2424
or use the below CDN link provided by [jsDelivr.com](https://www.jsdelivr.com/package/npm/simple-parallax-js):
2525

2626
```html
27-
<script src="https://cdn.jsdelivr.net/npm/simple-parallax-js@5.3.0/dist/simpleParallax.min.js"></script>
27+
<script src="https://cdn.jsdelivr.net/npm/simple-parallax-js@5.4.0/dist/simpleParallax.min.js"></script>
2828
```
2929

3030
### Via [npm/yarn](https://www.npmjs.com/package/simple-parallax-js)
@@ -74,6 +74,20 @@ You can also choose to apply the parallax on multiple images:
7474
const images = document.querySelectorAll('img');
7575
new simpleParallax(images);
7676
```
77+
78+
simpleParallax now works with video:
79+
80+
```html
81+
<video>
82+
<source src="video.mp4" type="video/mp4">
83+
</video>
84+
```
85+
86+
```javascript
87+
var video = document.getElementsByTagName('video');
88+
new simpleParallax(video);
89+
```
90+
7791
## Settings
7892

7993
Setting | Type | Default | Hint

dist/simpleParallax.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
2-
* simpleParallax - simpleParallax is a simple JavaScript library that gives your website parallax animations on any images,
3-
* @date: 07-04-2020 18:47:4,
4-
* @version: 5.3.0,
2+
* simpleParallax - simpleParallax is a simple JavaScript library that gives your website parallax animations on any images or videos,
3+
* @date: 08-04-2020 8:7:34,
4+
* @version: 5.4.0,
55
* @link: https://simpleparallax.com/
66
*/
77
(function webpackUniversalModuleDefinition(root, factory) {
@@ -184,20 +184,25 @@ var cssTransform = function cssTransform() {
184184

185185
/* harmony default export */ var helpers_cssTransform = (cssTransform());
186186
// CONCATENATED MODULE: ./src/helpers/isImageLoaded.js
187-
// check if image is fully loaded
188-
var isImageLoaded = function isImageLoaded(image) {
189-
// check if image is set as the parameter
190-
if (!image) {
187+
// check if media is fully loaded
188+
var isImageLoaded = function isImageLoaded(media) {
189+
//if the media is a video, return true
190+
if (media.tagName.toLowerCase() == 'video') {
191+
return true;
192+
} // check if media is set as the parameter
193+
194+
195+
if (!media) {
191196
return false;
192-
} // check if image has been 100% loaded
197+
} // check if media has been 100% loaded
193198

194199

195-
if (!image.complete) {
200+
if (!media.complete) {
196201
return false;
197-
} // check if the image is displayed
202+
} // check if the media is displayed
198203

199204

200-
if (typeof image.naturalWidth !== 'undefined' && image.naturalWidth === 0) {
205+
if (typeof media.naturalWidth !== 'undefined' && media.naturalWidth === 0) {
201206
return false;
202207
}
203208

@@ -545,6 +550,7 @@ function () {
545550
overflow: false,
546551
transition: 'cubic-bezier(0,0,0,1)',
547552
customContainer: false,
553+
customWrapper: false,
548554
maxTransition: 0
549555
};
550556
this.settings = Object.assign(this.defaults, options); // check if the browser handle the Intersection Observer API

dist/simpleParallax.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@
2020
/* div{
2121
overflow: hidden;
2222
} */
23-
img {
24-
max-width: 850px;
23+
img,
24+
video {
25+
width: 850px;
2526
height: auto;
2627
}
2728

2829
.simpleParallax {
2930
/* margin: 0 0 48px; */
3031
}
3132
</style>
33+
3234
</head>
3335
<body>
3436
<section class="container">
@@ -38,6 +40,13 @@
3840
<img class="up" src="https://simpleparallax.com/images/image03.jpg" alt="simpleParallax image" />
3941
</picture>
4042
</div>
43+
<div>
44+
<video width="400" autoplay>
45+
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
46+
<source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
47+
Your browser does not support HTML5 video.
48+
</video>
49+
</div>
4150
<div>
4251
<img class="up" src="https://simpleparallax.com/images/image03.jpg" alt="simpleParallax image" />
4352
</div>
@@ -280,5 +289,11 @@
280289
<img class="up" src="https://simpleparallax.com/images/image03.jpg" alt="simpleParallax image" />
281290
</div> -->
282291
</section>
292+
<!-- <script>
293+
console.log(document.querySelector('video'));
294+
document.querySelector('video').addEventListener('loadstart', function() {
295+
console.log('loaded');
296+
});
297+
</script> -->
283298
</body>
284299
</html>

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "simple-parallax-js",
3-
"version": "5.3.0",
4-
"description": "simpleParallax is a simple JavaScript library that gives your website parallax animations on any images",
3+
"version": "5.4.0",
4+
"description": "simpleParallax is a simple JavaScript library that gives your website parallax animations on any images or videos",
55
"homepage": "https://simpleparallax.com/",
66
"main": "./dist/simpleParallax.min.js",
77
"types": "./index.d.ts",
@@ -18,6 +18,7 @@
1818
"fast",
1919
"light",
2020
"image",
21+
"video",
2122
"effect",
2223
"vanilla",
2324
"es6"

src/helpers/isImageLoaded.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1-
// check if image is fully loaded
2-
const isImageLoaded = (image) => {
3-
// check if image is set as the parameter
4-
if (!image) {
1+
// check if media is fully loaded
2+
const isImageLoaded = (media) => {
3+
//if the media is a video, return true
4+
if (media.tagName.toLowerCase() == 'video') {
5+
return true;
6+
}
7+
8+
// check if media is set as the parameter
9+
if (!media) {
510
return false;
611
}
712

8-
// check if image has been 100% loaded
9-
if (!image.complete) {
13+
// check if media has been 100% loaded
14+
if (!media.complete) {
1015
return false;
1116
}
1217

13-
// check if the image is displayed
14-
if (typeof image.naturalWidth !== 'undefined' && image.naturalWidth === 0) {
18+
// check if the media is displayed
19+
if (typeof media.naturalWidth !== 'undefined' && media.naturalWidth === 0) {
1520
return false;
1621
}
1722

src/simpleParallax.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class SimpleParallax {
2121
overflow: false,
2222
transition: 'cubic-bezier(0,0,0,1)',
2323
customContainer: false,
24+
customWrapper: false,
2425
maxTransition: 0,
2526
};
2627

test/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import simpleParallax from '../src/simpleParallax';
88
let instanceUp;
99
const optionUp = {
1010
orientation: 'up',
11-
scale: 1.5,
12-
customWrapper: '.customWrapper'
11+
scale: 1.3,
12+
// customWrapper: '.customWrapper'
1313
// customContainer: document.querySelector('.container')
1414
};
1515
const imageUp = document.getElementsByTagName('img');
1616

17-
const images = document.querySelectorAll('img');
17+
const images = document.querySelectorAll('video, img');
1818
// images.forEach((image) => {
1919
const instance = new simpleParallax(images, optionUp);
2020
// });

0 commit comments

Comments
 (0)