1
1
/*!
2
2
* simpleParallax - simpleParallax is a simple JavaScript library that gives your website parallax animations on any images or videos,
3
- * @date : 07-06-2020 15:10:5 ,
3
+ * @date : 07-06-2020 15:53:39 ,
4
4
* @version : 5.4.1,
5
5
* @link : https://simpleparallax.com/
6
6
*/
@@ -112,10 +112,10 @@ __webpack_require__.r(__webpack_exports__);
112
112
__webpack_require__ . d ( __webpack_exports__ , "default" , function ( ) { return /* binding */ simpleParallax_SimpleParallax ; } ) ;
113
113
114
114
// CONCATENATED MODULE: ./src/helpers/isSupportedBrowser.js
115
- //need closest support
116
- //https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
117
- //need Intersection Observer support
118
- //https://github.com/w3c/IntersectionObserver/tree/master/polyfill
115
+ // need closest support
116
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
117
+ // need Intersection Observer support
118
+ // https://github.com/w3c/IntersectionObserver/tree/master/polyfill
119
119
var isSupportedBrowser = function isSupportedBrowser ( ) {
120
120
return Element . prototype . closest && 'IntersectionObserver' in window ;
121
121
} ;
@@ -170,7 +170,7 @@ var Viewport = /*#__PURE__*/function () {
170
170
var viewport = new Viewport ( ) ;
171
171
172
172
// CONCATENATED MODULE: ./src/helpers/convertToArray.js
173
- // check wether the element is a Node List, a HTML Collection or an array
173
+ // check whether the element is a Node List, a HTML Collection or an array
174
174
// return an array of nodes
175
175
var convertToArray = function convertToArray ( elements ) {
176
176
if ( NodeList . prototype . isPrototypeOf ( elements ) || HTMLCollection . prototype . isPrototypeOf ( elements ) ) return Array . from ( elements ) ;
@@ -198,8 +198,8 @@ var cssTransform = function cssTransform() {
198
198
// CONCATENATED MODULE: ./src/helpers/isImageLoaded.js
199
199
// check if media is fully loaded
200
200
var isImageLoaded = function isImageLoaded ( media ) {
201
- //if the media is a video, return true
202
- if ( media . tagName . toLowerCase ( ) == 'video' ) {
201
+ // if the media is a video, return true
202
+ if ( media . tagName . toLowerCase ( ) === 'video' ) {
203
203
return true ;
204
204
} // check if media is set as the parameter
205
205
@@ -264,7 +264,7 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
264
264
this . init ( ) ;
265
265
} else {
266
266
this . element . addEventListener ( 'load' , function ( ) {
267
- //timeout to ensure the image is fully loaded into the DOM
267
+ // timeout to ensure the image is fully loaded into the DOM
268
268
setTimeout ( function ( ) {
269
269
_this . init ( true ) ;
270
270
} , 50 ) ;
@@ -281,8 +281,8 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
281
281
if ( this . isInit ) return ;
282
282
283
283
if ( asyncInit ) {
284
- //in case the image is lazy loaded, the rangemax should be cleared
285
- //so it will be updated in the next getTranslateValue()
284
+ // in case the image is lazy loaded, the rangemax should be cleared
285
+ // so it will be updated in the next getTranslateValue()
286
286
this . rangeMax = null ;
287
287
} // check if element has not been already initialized with simpleParallax
288
288
@@ -327,8 +327,8 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
327
327
328
328
var elementToWrap = this . element . closest ( 'picture' ) || this . element ; // create a .simpleParallax wrapper container
329
329
330
- var wrapper = document . createElement ( 'div' ) ; //if there is a custom wrapper
331
- //override the wrapper with it
330
+ var wrapper = document . createElement ( 'div' ) ; // if there is a custom wrapper
331
+ // override the wrapper with it
332
332
333
333
if ( customWrapper ) {
334
334
wrapper = this . element . closest ( this . settings . customWrapper ) ;
@@ -350,7 +350,7 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
350
350
value : function unWrapElement ( ) {
351
351
var wrapper = this . elementContainer ; // get the customWrapper if any
352
352
353
- var customWrapper = this . settings . customWrapper && this . element . closest ( this . settings . customWrapper ) ; //if there is a custom wrapper, we jusy need to remove the class and style
353
+ var customWrapper = this . settings . customWrapper && this . element . closest ( this . settings . customWrapper ) ; // if there is a custom wrapper, we jusy need to remove the class and style
354
354
355
355
if ( customWrapper ) {
356
356
wrapper . classList . remove ( 'simpleParallax' ) ;
@@ -436,13 +436,15 @@ var parallax_ParallaxInstance = /*#__PURE__*/function () {
436
436
} , {
437
437
key : "intersectionObserverCallback" ,
438
438
value : function intersectionObserverCallback ( entries ) {
439
- for ( var i = entries . length - 1 ; i >= 0 ; i -- ) {
440
- if ( entries [ i ] . isIntersecting ) {
441
- this . isVisible = true ;
439
+ var _this3 = this ;
440
+
441
+ entries . forEach ( function ( entry ) {
442
+ if ( entry . isIntersecting ) {
443
+ _this3 . isVisible = true ;
442
444
} else {
443
- this . isVisible = false ;
445
+ _this3 . isVisible = false ;
444
446
}
445
- }
447
+ } ) ;
446
448
} // check if the current element is visible in the Viewport
447
449
// for browser that not support Intersection Observer API
448
450
@@ -542,14 +544,22 @@ function simpleParallax_toConsumableArray(arr) { return simpleParallax_arrayWith
542
544
543
545
function simpleParallax_nonIterableSpread ( ) { throw new TypeError ( "Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method." ) ; }
544
546
545
- function simpleParallax_unsupportedIterableToArray ( o , minLen ) { if ( ! o ) return ; if ( typeof o === "string" ) return simpleParallax_arrayLikeToArray ( o , minLen ) ; var n = Object . prototype . toString . call ( o ) . slice ( 8 , - 1 ) ; if ( n === "Object" && o . constructor ) n = o . constructor . name ; if ( n === "Map" || n === "Set" ) return Array . from ( o ) ; if ( n === "Arguments" || / ^ (?: U i | I ) n t (?: 8 | 1 6 | 3 2 ) (?: C l a m p e d ) ? A r r a y $ / . test ( n ) ) return simpleParallax_arrayLikeToArray ( o , minLen ) ; }
546
-
547
547
function simpleParallax_iterableToArray ( iter ) { if ( typeof Symbol !== "undefined" && Symbol . iterator in Object ( iter ) ) return Array . from ( iter ) ; }
548
548
549
549
function simpleParallax_arrayWithoutHoles ( arr ) { if ( Array . isArray ( arr ) ) return simpleParallax_arrayLikeToArray ( arr ) ; }
550
550
551
+ function _slicedToArray ( arr , i ) { return _arrayWithHoles ( arr ) || _iterableToArrayLimit ( arr , i ) || simpleParallax_unsupportedIterableToArray ( arr , i ) || _nonIterableRest ( ) ; }
552
+
553
+ function _nonIterableRest ( ) { throw new TypeError ( "Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method." ) ; }
554
+
555
+ function simpleParallax_unsupportedIterableToArray ( o , minLen ) { if ( ! o ) return ; if ( typeof o === "string" ) return simpleParallax_arrayLikeToArray ( o , minLen ) ; var n = Object . prototype . toString . call ( o ) . slice ( 8 , - 1 ) ; if ( n === "Object" && o . constructor ) n = o . constructor . name ; if ( n === "Map" || n === "Set" ) return Array . from ( o ) ; if ( n === "Arguments" || / ^ (?: U i | I ) n t (?: 8 | 1 6 | 3 2 ) (?: C l a m p e d ) ? A r r a y $ / . test ( n ) ) return simpleParallax_arrayLikeToArray ( o , minLen ) ; }
556
+
551
557
function simpleParallax_arrayLikeToArray ( arr , len ) { if ( len == null || len > arr . length ) len = arr . length ; for ( var i = 0 , arr2 = new Array ( len ) ; i < len ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; }
552
558
559
+ function _iterableToArrayLimit ( arr , i ) { if ( typeof Symbol === "undefined" || ! ( Symbol . iterator in Object ( arr ) ) ) return ; var _arr = [ ] ; var _n = true ; var _d = false ; var _e = undefined ; try { for ( var _i = arr [ Symbol . iterator ] ( ) , _s ; ! ( _n = ( _s = _i . next ( ) ) . done ) ; _n = true ) { _arr . push ( _s . value ) ; if ( i && _arr . length === i ) break ; } } catch ( err ) { _d = true ; _e = err ; } finally { try { if ( ! _n && _i [ "return" ] != null ) _i [ "return" ] ( ) ; } finally { if ( _d ) throw _e ; } } return _arr ; }
560
+
561
+ function _arrayWithHoles ( arr ) { if ( Array . isArray ( arr ) ) return arr ; }
562
+
553
563
function simpleParallax_classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
554
564
555
565
function simpleParallax_defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } }
@@ -562,15 +572,14 @@ function simpleParallax_createClass(Constructor, protoProps, staticProps) { if (
562
572
563
573
var isInit = false ;
564
574
var instances = [ ] ;
565
- var instancesLength ;
566
575
var frameID ;
567
576
var resizeID ;
568
577
569
578
var simpleParallax_SimpleParallax = /*#__PURE__*/ function ( ) {
570
579
function SimpleParallax ( elements , options ) {
571
580
simpleParallax_classCallCheck ( this , SimpleParallax ) ;
572
581
573
- if ( ! elements ) return ; //check if the browser support simpleParallax
582
+ if ( ! elements ) return ; // check if the browser support simpleParallax
574
583
575
584
if ( ! helpers_isSupportedBrowser ( ) ) return ;
576
585
this . elements = helpers_convertToArray ( elements ) ;
@@ -587,7 +596,11 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
587
596
this . settings = Object . assign ( this . defaults , options ) ;
588
597
589
598
if ( this . settings . customContainer ) {
590
- this . customContainer = helpers_convertToArray ( this . settings . customContainer ) [ 0 ] ;
599
+ var _convertToArray = helpers_convertToArray ( this . settings . customContainer ) ;
600
+
601
+ var _convertToArray2 = _slicedToArray ( _convertToArray , 1 ) ;
602
+
603
+ this . customContainer = _convertToArray2 [ 0 ] ;
591
604
}
592
605
593
606
this . lastPosition = - 1 ;
@@ -606,8 +619,8 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
606
619
instances = [ ] . concat ( simpleParallax_toConsumableArray ( this . elements . map ( function ( element ) {
607
620
return new parallax ( element , _this . settings ) ;
608
621
} ) ) , simpleParallax_toConsumableArray ( instances ) ) ; // update the instance length
609
-
610
- instancesLength = instances . length ; // only if this is the first simpleParallax init
622
+ // instancesLength = instances.length;
623
+ // only if this is the first simpleParallax init
611
624
612
625
if ( ! isInit ) {
613
626
// init the frame
@@ -629,21 +642,21 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
629
642
value : function handleResize ( ) {
630
643
// re-get all the viewport positions
631
644
viewport . setViewportAll ( this . customContainer ) ;
632
-
633
- for ( var i = instancesLength - 1 ; i >= 0 ; i -- ) {
645
+ instances . forEach ( function ( instance ) {
634
646
// re-get the current element offset
635
- instances [ i ] . getElementOffset ( ) ; // re-get the range if the current element
636
-
637
- instances [ i ] . getRangeMax ( ) ;
638
- } // force the request animation frame to fired
647
+ instance . getElementOffset ( ) ; // re-get the range if the current element
639
648
649
+ instance . getRangeMax ( ) ;
650
+ } ) ; // force the request animation frame to fired
640
651
641
652
this . lastPosition = - 1 ;
642
653
} // animation frame
643
654
644
655
} , {
645
656
key : "proceedRequestAnimationFrame" ,
646
657
value : function proceedRequestAnimationFrame ( ) {
658
+ var _this2 = this ;
659
+
647
660
// get the offset top of the viewport
648
661
viewport . setViewportTop ( this . customContainer ) ;
649
662
@@ -657,10 +670,9 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
657
670
658
671
viewport . setViewportBottom ( ) ; // proceed with the current element
659
672
660
- for ( var i = instancesLength - 1 ; i >= 0 ; i -- ) {
661
- this . proceedElement ( instances [ i ] ) ;
662
- } // callback the animationFrame
663
-
673
+ instances . forEach ( function ( instance ) {
674
+ _this2 . proceedElement ( instance ) ;
675
+ } ) ; // callback the animationFrame
664
676
665
677
frameID = window . requestAnimationFrame ( this . proceedRequestAnimationFrame ) ; // store the last position
666
678
@@ -692,35 +704,31 @@ var simpleParallax_SimpleParallax = /*#__PURE__*/function () {
692
704
} , {
693
705
key : "destroy" ,
694
706
value : function destroy ( ) {
695
- var _this2 = this ;
707
+ var _this3 = this ;
696
708
697
709
var instancesToDestroy = [ ] ; // remove all instances that need to be destroyed from the instances array
698
710
699
711
instances = instances . filter ( function ( instance ) {
700
- if ( _this2 . elements . includes ( instance . element ) ) {
712
+ if ( _this3 . elements . includes ( instance . element ) ) {
701
713
// push instance that need to be destroyed into instancesToDestroy
702
714
instancesToDestroy . push ( instance ) ;
703
715
return false ;
704
716
}
705
717
706
718
return instance ;
707
719
} ) ;
708
-
709
- for ( var i = instancesToDestroy . length - 1 ; i >= 0 ; i -- ) {
720
+ instancesToDestroy . forEach ( function ( instance ) {
710
721
// unset style
711
- instancesToDestroy [ i ] . unSetStyle ( ) ;
722
+ instance . unSetStyle ( ) ;
712
723
713
- if ( this . settings . overflow === false ) {
724
+ if ( _this3 . settings . overflow === false ) {
714
725
// if overflow option is set to false
715
726
// unwrap the element from .simpleParallax wrapper container
716
- instancesToDestroy [ i ] . unWrapElement ( ) ;
727
+ instance . unWrapElement ( ) ;
717
728
}
718
- } // update the instance length var
719
-
720
-
721
- instancesLength = instances . length ; // if no instances left, remove the raf and resize event = simpleParallax fully destroyed
729
+ } ) ; // if no instances left, remove the raf and resize event = simpleParallax fully destroyed
722
730
723
- if ( ! instancesLength ) {
731
+ if ( ! instances . length ) {
724
732
// cancel the animation frame
725
733
window . cancelAnimationFrame ( frameID ) ; // detach the resize event
726
734
0 commit comments