vevet
Version:
Vevet is a JavaScript library for creative development that simplifies crafting rich interactions like split text animations, carousels, marquees, preloading, and more.
39 lines • 1.15 kB
JavaScript
import { SnapLogic } from '..';
import { IDLE_DEBOUNCE, WHEEL_DEBOUNCE } from '../../props';
export class SnapIdle extends SnapLogic {
constructor(ctx) {
super(ctx);
this.callbacks.on('update', () => this._handleUpdate(), {
protected: true,
});
this.addDestructor(() => this._clear());
}
/** Check if idle */
get isIdle() {
return (!this.isSwiping &&
!this.hasInertia &&
!this.isInterpolating &&
!this.isTransitioning &&
!this.isWheeling);
}
/** Handle Snap update */
_handleUpdate() {
this._clear();
const debounce = Math.max(IDLE_DEBOUNCE, WHEEL_DEBOUNCE) + 10;
this._timeout = setTimeout(() => this._handleTimeout(), debounce);
}
/** Handle timeout action */
_handleTimeout() {
if (this.isIdle) {
this.callbacks.emit('idle', undefined);
}
}
/** Clear timeout reference */
_clear() {
if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = undefined;
}
}
}
//# sourceMappingURL=index.js.map