@mangoweb/parallax
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -17,2 +17,3 @@ "use strict"; | ||
var scripts_base_1 = require("@mangoweb/scripts-base"); | ||
var light_bounds_1 = require("light-bounds"); | ||
var PARALLAX_REACH = 1; // 100vh | ||
@@ -28,8 +29,7 @@ function clamp(min, value, max) { | ||
var reachDistance = window.innerHeight * PARALLAX_REACH; | ||
var offset = clamp(-1, -(_this.getElementYCenter() - (window.scrollY + window.innerHeight / 2)) / reachDistance, 1); | ||
var offset = clamp(-1, (_this.getElementYCenter() - (window.scrollY + window.innerHeight / 2)) / reachDistance, 1); | ||
_this.el.style.setProperty("--" + _this.getPropOrElse('customProperty', 'parallax'), "" + offset); | ||
}; | ||
_this.getElementYCenter = function () { | ||
// @TODO: debounce | ||
var rect = _this.el.getBoundingClientRect(); | ||
var rect = light_bounds_1.lightBounds(_this.el); | ||
return window.scrollY + rect.top + rect.height / 2; | ||
@@ -36,0 +36,0 @@ }; |
{ | ||
"name": "@mangoweb/parallax", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Watches elements vertical position in viewport.", | ||
@@ -39,3 +39,6 @@ "main": "lib/index.js", | ||
"@mangoweb/scripts-base": "0.0.12" | ||
}, | ||
"dependencies": { | ||
"light-bounds": "0.0.6" | ||
} | ||
} |
import { Component } from '@mangoweb/scripts-base' | ||
import { lightBounds } from 'light-bounds' | ||
@@ -23,3 +24,3 @@ interface ParallaxProps { | ||
const reachDistance = window.innerHeight * PARALLAX_REACH | ||
const offset = clamp(-1, -(this.getElementYCenter() - (window.scrollY + window.innerHeight / 2)) / reachDistance, 1) | ||
const offset = clamp(-1, (this.getElementYCenter() - (window.scrollY + window.innerHeight / 2)) / reachDistance, 1) | ||
@@ -30,6 +31,5 @@ this.el.style.setProperty(`--${this.getPropOrElse('customProperty', 'parallax')}`, `${offset}`) | ||
getElementYCenter = () => { | ||
// @TODO: debounce | ||
const rect = this.el.getBoundingClientRect() | ||
const rect = lightBounds(this.el) | ||
return window.scrollY + rect.top + rect.height / 2 | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6739
2
+ Addedlight-bounds@0.0.6
+ Addedlight-bounds@0.0.6(transitive)