rytm-webflow 2.1.7 → 2.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rytm-webflow",
3
- "version": "2.1.7",
3
+ "version": "2.1.8",
4
4
  "description": "rytm webflow pack - ASwap, ShowUp",
5
5
  "main": "scripts/index.js",
6
6
  "scripts": {
@@ -4,6 +4,7 @@ import View from './View';
4
4
  import scrollController from './../showup/ScrollController';
5
5
  import { getWebflowAnimationProps, parseProps } from './../lib/dataTweenParser';
6
6
  import { getScrollMagicSceneProps } from './../lib/dataScrollMagicParser';
7
+ import { elementIsVisibleInViewport } from '../lib/helpers'
7
8
 
8
9
  // data-webview-... (aswap show / hide)
9
10
  const DATA_ATTR_WEBVIEW_INIT = "webview-initial";
@@ -216,9 +217,7 @@ class WebflowView extends View {
216
217
  });
217
218
  // on scene add event
218
219
  scene.on("add", (e) => {
219
- // check if element is already in view
220
- const rect = el.getBoundingClientRect();
221
- if (rect.top >= 0 && rect.bottom <= window.innerHeight) {
220
+ if (elementIsVisibleInViewport(el, true)) {
222
221
  // element is in view - animate IN
223
222
  gsap.to(el, {
224
223
  duration: propsShow.time,
package/scripts/index.js CHANGED
@@ -11,6 +11,7 @@ import scrollController from './showup/ScrollController'
11
11
  import showUp from './showup/ShowUp'
12
12
  import { getWebflowAnimationProps, getWebflowProps, getParallaxProps, parseProps } from './lib/dataTweenParser'
13
13
  import { getScrollMagicSceneProps } from './lib/dataScrollMagicParser'
14
+ import { elementIsVisibleInViewport } from './lib/helpers'
14
15
 
15
16
  export default {
16
17
  aswap: aswapInstance,
@@ -29,5 +30,6 @@ export default {
29
30
  getWebflowProps,
30
31
  getParallaxProps,
31
32
  parseProps,
32
- getScrollMagicSceneProps
33
+ getScrollMagicSceneProps,
34
+ elementIsVisibleInViewport,
33
35
  }
@@ -0,0 +1,10 @@
1
+
2
+ export const elementIsVisibleInViewport = (el, partiallyVisible = true) => {
3
+ const { top, left, bottom, right } = el.getBoundingClientRect();
4
+ const { innerHeight, innerWidth } = window;
5
+ return partiallyVisible
6
+ ? ((top > 0 && top < innerHeight) ||
7
+ (bottom > 0 && bottom < innerHeight)) &&
8
+ ((left > 0 && left < innerWidth) || (right > 0 && right < innerWidth))
9
+ : top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;
10
+ }