Skip to content

armgit / anime

Public Imported from GitHub
0

JavaScript animation engine

fix(scroll): fixes threshold with scale on parent

almir89d3c55d0bf2
diff --git a/lib/anime.esm.js b/lib/anime.esm.js
index fd6b7e02..ab195e3d 100644
--- a/lib/anime.esm.js
+++ b/lib/anime.esm.js
@@ -9,18 +9,18 @@
/**
* @typedef {Object} DefaultsParams
- * @property {number|string} [id]
+ * @property {Number|String} [id]
* @property {PercentageKeyframes|DurationKeyframes} [keyframes]
* @property {EasingParam} [playbackEase]
- * @property {number} [playbackRate]
- * @property {number} [frameRate]
- * @property {number|boolean} [loop]
- * @property {boolean} [reversed]
- * @property {boolean} [alternate]
- * @property {boolean|ScrollObserver} [autoplay]
- * @property {number|FunctionValue} [duration]
- * @property {number|FunctionValue} [delay]
- * @property {number} [loopDelay]
+ * @property {Number} [playbackRate]
+ * @property {Number} [frameRate]
+ * @property {Number|Boolean} [loop]
+ * @property {Boolean} [reversed]
+ * @property {Boolean} [alternate]
+ * @property {Boolean|ScrollObserver} [autoplay]
+ * @property {Number|FunctionValue} [duration]
+ * @property {Number|FunctionValue} [delay]
+ * @property {Number} [loopDelay]
* @property {EasingParam} [ease]
* @property {'none'|'replace'|'blend'|compositionTypes} [composition]
* @property {(v: any) => any} [modifier]
@@ -627,7 +627,7 @@ const interpolate = (start, end, progress) => start + (end - start) * progress;
* @param {Number} v
* @return {Number}
*/
-const clampInfinity = v => v === Infinity ? maxValue : v === -Infinity ? -1e12 : v;
+const clampInfinity = v => v === Infinity ? maxValue : v === -Infinity ? -maxValue : v;
/**
* @param {Number} v
@@ -1604,7 +1604,7 @@ const createDrawableProxy = ($el, start, end) => {
// const v1 = round(+value.slice(0, spaceIndex), precision);
// const v2 = round(+value.slice(spaceIndex + 1), precision);
const scaleFactor = getScaleFactor($scalled);
- const os = v1 * -1e3 * scaleFactor;
+ const os = v1 * -pathLength * scaleFactor;
const d1 = (v2 * pathLength * scaleFactor) + os;
const d2 = (pathLength * scaleFactor +
((v1 === 0 && v2 === 1) || (v1 === 1 && v2 === 0) ? 0 : 10 * scaleFactor) - d1);
@@ -5160,7 +5160,7 @@ class Spring {
this.m = clamp(setValue(parameters.mass, 1), 0, K);
this.s = clamp(setValue(parameters.stiffness, 100), 1, K);
this.d = clamp(setValue(parameters.damping, 10), .1, K);
- this.v = clamp(setValue(parameters.velocity, 0), -1e3, K);
+ this.v = clamp(setValue(parameters.velocity, 0), -K, K);
this.w0 = 0;
this.zeta = 0;
this.wd = 0;
@@ -5238,7 +5238,7 @@ class Spring {
}
set velocity(v) {
- this.v = clamp(setValue(v, 0), -1e3, K);
+ this.v = clamp(setValue(v, 0), -K, K);
this.compute();
}
}
@@ -5508,7 +5508,7 @@ class Draggable {
/** @type {[Number, Number, Number, Number]} */
this.dragArea = [0, 0, 0, 0]; // x, y, w, h
/** @type {[Number, Number, Number, Number]} */
- this.containerBounds = [-1e12, maxValue, maxValue, -1e12]; // t, r, b, l
+ this.containerBounds = [-maxValue, maxValue, maxValue, -maxValue]; // t, r, b, l
/** @type {[Number, Number, Number, Number]} */
this.scrollBounds = [0, 0, 0, 0]; // t, r, b, l
/** @type {[Number, Number, Number, Number]} */
@@ -5977,10 +5977,10 @@ class Draggable {
const canScroll = this.canScroll;
if (!this.containerArray && this.isOutOfBounds(scrollBounds, x, y)) {
const [ st, sr, sb, sl ] = scrollBounds;
- const t = round(clamp(y - st, -1e12, 0), 0);
+ const t = round(clamp(y - st, -maxValue, 0), 0);
const r = round(clamp(x - sr, 0, maxValue), 0);
const b = round(clamp(y - sb, 0, maxValue), 0);
- const l = round(clamp(x - sl, -1e12, 0), 0);
+ const l = round(clamp(x - sl, -maxValue, 0), 0);
new JSAnimation(scroll, {
x: round(scroll.x + (l ? l - gap : r ? r + gap : 0), 0),
y: round(scroll.y + (t ? t - gap : b ? b + gap : 0), 0),
@@ -6787,8 +6787,8 @@ class ScrollContainer {
height = this.winHeight;
} else {
const elRect = $el.getBoundingClientRect();
- width = elRect.width;
- height = elRect.height;
+ width = $el.clientWidth;
+ height = $el.clientHeight;
this.top = elRect.top;
this.left = elRect.left;
}
@@ -7439,7 +7439,7 @@ class ScrollObserver {
if (syncSmooth && isNum(syncSmooth)) {
if (/** @type {Number} */(syncSmooth) < 1) {
const step = 0.0001;
- const snap = lp < p && p === 1 ? step : lp > p && !p ? -1e-4 : 0;
+ const snap = lp < p && p === 1 ? step : lp > p && !p ? -step : 0;
p = round(lerp(lp, p, interpolate(.01, .2, /** @type {Number} */(syncSmooth)), false) + snap, 6);
}
} else if (syncEase) {
diff --git a/src/scroll.js b/src/scroll.js
index b220fe3c..82e2710b 100644
--- a/src/scroll.js
+++ b/src/scroll.js
@@ -210,8 +210,8 @@ class ScrollContainer {
height = this.winHeight;
} else {
const elRect = $el.getBoundingClientRect();
- width = elRect.width;
- height = elRect.height;
+ width = $el.clientWidth;
+ height = $el.clientHeight;
this.top = elRect.top;
this.left = elRect.left;
}
diff --git a/types/index.js b/types/index.js
index 64d8d92d..e5a2423c 100644
--- a/types/index.js
+++ b/types/index.js
@@ -248,7 +248,7 @@ const interpolate = (start, end, progress) => start + (end - start) * progress;
* @param {Number} v
* @return {Number}
*/
-const clampInfinity = v => v === Infinity ? maxValue : v === -Infinity ? -1e12 : v;
+const clampInfinity = v => v === Infinity ? maxValue : v === -Infinity ? -maxValue : v;
/**
* @param {Number} v
* @return {Number}
@@ -1158,7 +1158,7 @@ const createDrawableProxy = ($el, start, end) => {
// const v1 = round(+value.slice(0, spaceIndex), precision);
// const v2 = round(+value.slice(spaceIndex + 1), precision);
const scaleFactor = getScaleFactor($scalled);
- const os = v1 * -1e3 * scaleFactor;
+ const os = v1 * -pathLength * scaleFactor;
const d1 = (v2 * pathLength * scaleFactor) + os;
const d2 = (pathLength * scaleFactor +
((v1 === 0 && v2 === 1) || (v1 === 1 && v2 === 0) ? 0 : 10 * scaleFactor) - d1);
@@ -4460,7 +4460,7 @@ class Spring {
this.m = clamp(setValue(parameters.mass, 1), 0, K);
this.s = clamp(setValue(parameters.stiffness, 100), 1, K);
this.d = clamp(setValue(parameters.damping, 10), .1, K);
- this.v = clamp(setValue(parameters.velocity, 0), -1e3, K);
+ this.v = clamp(setValue(parameters.velocity, 0), -K, K);
this.w0 = 0;
this.zeta = 0;
this.wd = 0;
@@ -4530,7 +4530,7 @@ class Spring {
return this.v;
}
set velocity(v) {
- this.v = clamp(setValue(v, 0), -1e3, K);
+ this.v = clamp(setValue(v, 0), -K, K);
this.compute();
}
}
@@ -4802,7 +4802,7 @@ class Draggable {
/** @type {[Number, Number, Number, Number]} */
this.dragArea = [0, 0, 0, 0]; // x, y, w, h
/** @type {[Number, Number, Number, Number]} */
- this.containerBounds = [-1e12, maxValue, maxValue, -1e12]; // t, r, b, l
+ this.containerBounds = [-maxValue, maxValue, maxValue, -maxValue]; // t, r, b, l
/** @type {[Number, Number, Number, Number]} */
this.scrollBounds = [0, 0, 0, 0]; // t, r, b, l
/** @type {[Number, Number, Number, Number]} */
@@ -5266,10 +5266,10 @@ class Draggable {
const canScroll = this.canScroll;
if (!this.containerArray && this.isOutOfBounds(scrollBounds, x, y)) {
const [st, sr, sb, sl] = scrollBounds;
- const t = round(clamp(y - st, -1e12, 0), 0);
+ const t = round(clamp(y - st, -maxValue, 0), 0);
const r = round(clamp(x - sr, 0, maxValue), 0);
const b = round(clamp(y - sb, 0, maxValue), 0);
- const l = round(clamp(x - sl, -1e12, 0), 0);
+ const l = round(clamp(x - sl, -maxValue, 0), 0);
new JSAnimation(scroll, {
x: round(scroll.x + (l ? l - gap : r ? r + gap : 0), 0),
y: round(scroll.y + (t ? t - gap : b ? b + gap : 0), 0),
@@ -6033,8 +6033,8 @@ class ScrollContainer {
}
else {
const elRect = $el.getBoundingClientRect();
- width = elRect.width;
- height = elRect.height;
+ width = $el.clientWidth;
+ height = $el.clientHeight;
this.top = elRect.top;
this.left = elRect.left;
}
@@ -6669,7 +6669,7 @@ class ScrollObserver {
if (syncSmooth && isNum(syncSmooth)) {
if ( /** @type {Number} */(syncSmooth) < 1) {
const step = 0.0001;
- const snap = lp < p && p === 1 ? step : lp > p && !p ? -1e-4 : 0;
+ const snap = lp < p && p === 1 ? step : lp > p && !p ? -step : 0;
p = round(lerp(lp, p, interpolate(.01, .2, /** @type {Number} */ (syncSmooth)), false) + snap, 6);
}
}