File tree Expand file tree Collapse file tree 3 files changed +22
-21
lines changed Expand file tree Collapse file tree 3 files changed +22
-21
lines changed Original file line number Diff line number Diff line change 11import {
22 getParallaxOffsets ,
3+ isElementInView ,
34 parseValueAndUnit ,
45 testForPassiveScroll ,
56} from '../utils/index' ;
@@ -102,7 +103,7 @@ function ParallaxController() {
102103 if ( element . props . disabled ) return ;
103104
104105 // check if the element is in view then
105- const isInView = _isElementInView ( element ) ;
106+ const isInView = isElementInView ( element , windowHeight , scrollY ) ;
106107
107108 // set styles if it is
108109 if ( isInView ) _setParallaxStyles ( element ) ;
@@ -266,26 +267,6 @@ function ParallaxController() {
266267 } ;
267268 }
268269
269- /**
270- * Takes a parallax element and returns whether the element
271- * is in view based on the cached position of the element,
272- * current scroll position and the window height.
273- * @param {object } element
274- * @return {boolean } isInView
275- */
276- function _isElementInView ( element ) {
277- const top = element . attributes . top - scrollY ;
278- const bottom = element . attributes . bottom - scrollY ;
279-
280- const topInView = top >= 0 && top <= windowHeight ;
281- const bottomInView = bottom >= 0 && bottom <= windowHeight ;
282- const covering = top <= 0 && bottom >= windowHeight ;
283-
284- const isInView = topInView || bottomInView || covering ;
285-
286- return isInView ;
287- }
288-
289270 /**
290271 * Takes a parallax element and set the styles based on the
291272 * offsets and percent the element has moved though the viewport.
Original file line number Diff line number Diff line change 11export clamp from './clamp' ;
22export getParallaxOffsets from './getParallaxOffsets' ;
3+ export isElementInView from './isElementInView' ;
34export parseValueAndUnit from './parseValueAndUnit' ;
45export scaleBetween from './scaleBetween' ;
56
Original file line number Diff line number Diff line change 1+ /**
2+ * Takes a parallax element and returns whether the element
3+ * is in view based on the cached position of the element,
4+ * current scroll position and the window height.
5+ * @param {object } element
6+ * @return {boolean } isInView
7+ */
8+ export default function isElementInView ( element , windowHeight , scrollY ) {
9+ const top = element . attributes . top - scrollY ;
10+ const bottom = element . attributes . bottom - scrollY ;
11+
12+ const topInView = top >= 0 && top <= windowHeight ;
13+ const bottomInView = bottom >= 0 && bottom <= windowHeight ;
14+ const covering = top <= 0 && bottom >= windowHeight ;
15+
16+ const isInView = topInView || bottomInView || covering ;
17+
18+ return isInView ;
19+ }
You can’t perform that action at this time.
0 commit comments