@adoratorio/hades
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -26,8 +26,12 @@ import { MODE, DIRECTION, TRACK, HadesOptions, Boundries, Vec2, Easing } from "./declarations"; | ||
private scrollbar; | ||
private stopNeedEmission; | ||
private startNeedEmission; | ||
amount: Vec2; | ||
velocity: Vec2; | ||
running: boolean; | ||
still: boolean; | ||
constructor(options: Partial<HadesOptions>); | ||
private frame; | ||
private scroll; | ||
private emitStillChange; | ||
scrollTo(position: Partial<Vec2>, duration: number): void; | ||
@@ -34,0 +38,0 @@ play(): void; |
@@ -32,5 +32,8 @@ "use strict"; | ||
this.scrollbar = null; | ||
this.stopNeedEmission = false; | ||
this.startNeedEmission = true; | ||
this.amount = { x: 0, y: 0 }; | ||
this.velocity = { x: 0, y: 0 }; | ||
this.running = false; | ||
this.still = true; | ||
var defaults = { | ||
@@ -172,3 +175,23 @@ mode: declarations_1.MODE.VIRTUAL, | ||
}; | ||
// Use 4 digits precision | ||
this.velocity.x = parseFloat(this.velocity.x.toFixed(4)); | ||
this.velocity.y = parseFloat(this.velocity.y.toFixed(4)); | ||
this.prevAmount = current; | ||
// Check if the scroll is still animating or not | ||
if (this.velocity.y === 0 && this.velocity.x === 0) { | ||
this.still = true; | ||
if (this.stopNeedEmission) { | ||
this.emitStillChange('stop'); | ||
this.stopNeedEmission = false; | ||
this.startNeedEmission = true; | ||
} | ||
} | ||
else { | ||
this.still = false; | ||
if (this.startNeedEmission) { | ||
this.emitStillChange('start'); | ||
this.startNeedEmission = false; | ||
this.stopNeedEmission = true; | ||
} | ||
} | ||
// Update scrollbar tracks | ||
@@ -231,2 +254,9 @@ if (this.options.scrollbar !== null && this.scrollbar !== null) { | ||
}; | ||
Hades.prototype.emitStillChange = function (type) { | ||
if (this.options.emitGlobal) { | ||
var eventInit = {}; | ||
var customEvent = new CustomEvent("hades-" + type, eventInit); | ||
window.dispatchEvent(customEvent); | ||
} | ||
}; | ||
Hades.prototype.scrollTo = function (position, duration) { | ||
@@ -233,0 +263,0 @@ if (this.virtual) { |
{ | ||
"name": "@adoratorio/hades", | ||
"version": "0.1.9", | ||
"version": "0.1.10", | ||
"description": "A smooth scrollbar based on Hermes, scroll down 'till hell", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
39502
777