1
1
/*!
2
2
* simpleParallax - simpleParallax is a simple JavaScript library that gives your website parallax animations on any images,
3
- * @date : 06-12-2019 13:53:55 ,
3
+ * @date : 06-12-2019 17:9:59 ,
4
4
* @version : 5.1.0,
5
5
* @link : https://simpleparallax.com/
6
6
*/
@@ -129,8 +129,9 @@ function () {
129
129
130
130
_createClass ( Viewport , [ {
131
131
key : "setViewportTop" ,
132
- value : function setViewportTop ( ) {
133
- this . positions . top = window . pageYOffset ;
132
+ value : function setViewportTop ( container ) {
133
+ //if this is a custom container, user the scrollTop
134
+ this . positions . top = container ? container . scrollTop : window . pageYOffset ;
134
135
return this . positions ;
135
136
}
136
137
} , {
@@ -139,18 +140,14 @@ function () {
139
140
this . positions . bottom = this . positions . top + this . positions . height ;
140
141
return this . positions ;
141
142
}
142
- } , {
143
- key : "setViewportHeight" ,
144
- value : function setViewportHeight ( ) {
145
- this . positions . height = document . documentElement . clientHeight ;
146
- return this . positions ;
147
- }
148
143
} , {
149
144
key : "setViewportAll" ,
150
- value : function setViewportAll ( ) {
151
- this . positions . top = window . pageYOffset ;
145
+ value : function setViewportAll ( container ) {
146
+ //if this is a custom container, user the scrollTop
147
+ this . positions . top = container ? container . scrollTop : window . pageYOffset ; //if this is a custom container, get the height from the custom container itself
148
+
149
+ this . positions . height = container ? document . querySelector ( '.container' ) . clientHeight : document . documentElement . clientHeight ;
152
150
this . positions . bottom = this . positions . top + this . positions . height ;
153
- this . positions . height = document . documentElement . clientHeight ;
154
151
return this . positions ;
155
152
}
156
153
} ] ) ;
@@ -347,7 +344,14 @@ function () {
347
344
348
345
this . elementHeight = positions . height ; // get offset top
349
346
350
- this . elementTop = positions . top + simpleParallax_viewport . positions . top ; // get offset bottom
347
+ this . elementTop = positions . top + simpleParallax_viewport . positions . top ; //if there is a custom container
348
+
349
+ if ( this . settings . customContainer ) {
350
+ //we need to do some calculation to get the position from the parent rather than the viewport
351
+ var parentPositions = document . querySelector ( this . settings . customContainer ) . getBoundingClientRect ( ) ;
352
+ this . elementTop = positions . top - parentPositions . top + simpleParallax_viewport . positions . top ;
353
+ } // get offset bottom
354
+
351
355
352
356
this . elementBottom = this . elementHeight + this . elementTop ;
353
357
} // build the Threshold array to cater change for every pixel scrolled
@@ -508,11 +512,17 @@ function () {
508
512
orientation : 'up' ,
509
513
scale : 1.3 ,
510
514
overflow : false ,
511
- transition : 'cubic-bezier(0,0,0,1)'
515
+ transition : 'cubic-bezier(0,0,0,1)' ,
516
+ customContainer : false
512
517
} ;
513
518
this . settings = Object . assign ( this . defaults , options ) ; // check if the browser handle the Intersection Observer API
514
519
515
520
if ( ! ( 'IntersectionObserver' in window ) ) intersectionObserverAvailable = false ;
521
+
522
+ if ( this . settings . customContainer ) {
523
+ this . customContainer = document . querySelector ( this . settings . customContainer ) ;
524
+ }
525
+
516
526
this . lastPosition = - 1 ;
517
527
this . resizeIsDone = this . resizeIsDone . bind ( this ) ;
518
528
this . handleResize = this . handleResize . bind ( this ) ;
@@ -523,7 +533,7 @@ function () {
523
533
simpleParallax_createClass ( SimpleParallax , [ {
524
534
key : "init" ,
525
535
value : function init ( ) {
526
- simpleParallax_viewport . setViewportAll ( ) ;
536
+ simpleParallax_viewport . setViewportAll ( this . customContainer ) ;
527
537
528
538
for ( var i = this . elements . length - 1 ; i >= 0 ; i -- ) {
529
539
var instance = new parallax ( this . elements [ i ] , this . settings ) ;
@@ -552,7 +562,7 @@ function () {
552
562
key : "handleResize" ,
553
563
value : function handleResize ( ) {
554
564
// re-get all the viewport positions
555
- simpleParallax_viewport . setViewportAll ( ) ;
565
+ simpleParallax_viewport . setViewportAll ( this . customContainer ) ;
556
566
557
567
for ( var i = instancesLength - 1 ; i >= 0 ; i -- ) {
558
568
// re-get the current element offset
@@ -569,7 +579,7 @@ function () {
569
579
key : "proceedRequestAnimationFrame" ,
570
580
value : function proceedRequestAnimationFrame ( ) {
571
581
// get the offset top of the viewport
572
- simpleParallax_viewport . setViewportTop ( ) ;
582
+ simpleParallax_viewport . setViewportTop ( this . customContainer ) ;
573
583
574
584
if ( this . lastPosition === simpleParallax_viewport . positions . top ) {
575
585
// if last position if the same than the curent one
@@ -595,9 +605,10 @@ function () {
595
605
key : "proceedElement" ,
596
606
value : function proceedElement ( instance ) {
597
607
var isVisible = false ; // is not support for Intersection Observer API
608
+ // or if this is a custom container
598
609
// use old function to check if element visible
599
610
600
- if ( ! intersectionObserverAvailable ) {
611
+ if ( ! intersectionObserverAvailable || this . customContainer ) {
601
612
isVisible = instance . checkIfVisible ( ) ; // if support
602
613
// use response from Intersection Observer API Callback
603
614
} else {
0 commit comments