vevet
Version:
Vevet is a JavaScript library for creative development that simplifies crafting rich interactions like split text animations, carousels, marquees, preloading, and more.
47 lines • 1.38 kB
JavaScript
import { isFiniteNumber } from '../../../../internal/isFiniteNumber';
import { SnapLogic } from '..';
export class SnapInterval extends SnapLogic {
constructor(ctx, _onPrev, _onNext) {
super(ctx);
this._onPrev = _onPrev;
this._onNext = _onNext;
this.callbacks.on('update', () => this._handleUpdate(), {
protected: true,
});
this.addDestructor(() => this._clearInterval());
}
get allowInterval() {
return (!this.isSwiping &&
!this.hasInertia &&
!this.isTransitioning &&
!this.isInterpolating &&
isFiniteNumber(this.props.interval));
}
/** Handle Snap update */
_handleUpdate() {
if (!this.allowInterval) {
this._clearInterval();
return;
}
if (!this._interval) {
this._interval = setInterval(() => this._handleInterval(), this.props.interval);
}
}
/** Handle interval action */
_handleInterval() {
if (this.props.intervalDirection === 'prev') {
this._onPrev();
}
else {
this._onNext();
}
}
/** Clear interval */
_clearInterval() {
if (this._interval) {
clearInterval(this._interval);
this._interval = undefined;
}
}
}
//# sourceMappingURL=index.js.map