rytm-webflow 2.1.6 → 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.6",
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";
@@ -214,6 +215,19 @@ class WebflowView extends View {
214
215
  });
215
216
  }
216
217
  });
218
+ // on scene add event
219
+ scene.on("add", (e) => {
220
+ if (elementIsVisibleInViewport(el, true)) {
221
+ // element is in view - animate IN
222
+ gsap.to(el, {
223
+ duration: propsShow.time,
224
+ ...propsShow.tween,
225
+ onComplete: () => {
226
+ el.classList.add(CLASS_NAME_WEBSCROLL_FIRED);
227
+ }
228
+ });
229
+ }
230
+ });
217
231
  scene.addTo(scrollController.get());
218
232
  this.scenes.push(scene);
219
233
  }
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
+ }