@mangoweb/parallax
Advanced tools
Comparing version 0.0.5 to 0.0.6
import { Component } from '@mangoweb/scripts-base'; | ||
declare const easings: { | ||
linear: (x: number) => number; | ||
easeIn: (x: number) => number; | ||
easeOut: (x: number) => number; | ||
easeInOut: (x: number) => number; | ||
}; | ||
interface ParallaxProps { | ||
customProperty?: string; | ||
easing?: keyof typeof easings; | ||
} | ||
@@ -12,0 +5,0 @@ export declare class Parallax extends Component<ParallaxProps> { |
@@ -18,8 +18,2 @@ "use strict"; | ||
var light_bounds_1 = require("light-bounds"); | ||
var easings = { | ||
linear: function (x) { return x; }, | ||
easeIn: function (x) { return x * x; }, | ||
easeOut: function (x) { return x * (2 - x); }, | ||
easeInOut: function (x) { return (x < 0.5 ? 2 * x * x : -1 + (4 - 2 * x) * x); }, | ||
}; | ||
var PARALLAX_REACH = 1; // 100vh | ||
@@ -35,4 +29,3 @@ function clamp(min, value, max) { | ||
var reachDistance = window.innerHeight * PARALLAX_REACH; | ||
var easing = easings[_this.getPropOrElse('easing', 'linear')]; | ||
var offset = easing(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); | ||
@@ -39,0 +32,0 @@ }; |
{ | ||
"name": "@mangoweb/parallax", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Watches elements vertical position in viewport.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
import { Component } from '@mangoweb/scripts-base' | ||
import { lightBounds } from 'light-bounds' | ||
const easings = { | ||
linear: (x: number) => x, | ||
easeIn: (x: number) => x * x, | ||
easeOut: (x: number) => x * (2 - x), | ||
easeInOut: (x: number) => (x < 0.5 ? 2 * x * x : -1 + (4 - 2 * x) * x), | ||
} | ||
interface ParallaxProps { | ||
customProperty?: string | ||
easing?: keyof typeof easings | ||
} | ||
@@ -32,6 +24,3 @@ | ||
const reachDistance = window.innerHeight * PARALLAX_REACH | ||
const easing = easings[this.getPropOrElse('easing', 'linear')] | ||
const offset = easing( | ||
clamp(-1, (this.getElementYCenter() - (window.scrollY + window.innerHeight / 2)) / reachDistance, 1) | ||
) | ||
const offset = clamp(-1, (this.getElementYCenter() - (window.scrollY + window.innerHeight / 2)) / reachDistance, 1) | ||
@@ -38,0 +27,0 @@ this.el.style.setProperty(`--${this.getPropOrElse('customProperty', 'parallax')}`, `${offset}`) |
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
6644
88