Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
move(delta: number) {
delta = this.hasScroll ? delta : 0
this.movingDirection =
delta > 0
? Direction.Negative
: delta < 0
? Direction.Positive
: Direction.Default
let newPos = this.currentPos + delta
// Slow down or stop if outside of the boundaries
if (newPos > this.minScrollPos || newPos < this.maxScrollPos) {
if (
(newPos > this.minScrollPos && this.options.bounces[0]) ||
(newPos < this.maxScrollPos && this.options.bounces[1])
) {
newPos = this.currentPos + delta / 3
} else {
newPos =
newPos > this.minScrollPos ? this.minScrollPos : this.maxScrollPos
let momentumInfo: {
destination?: number
duration?: number
} = {
duration: 0
}
const absDist = Math.abs(this.currentPos - this.startPos)
// start momentum animation if needed
if (
this.options.momentum &&
duration < this.options.momentumLimitTime &&
absDist > this.options.momentumLimitDistance
) {
const wrapperSize =
(this.direction === Direction.Negative && this.options.bounces[0]) ||
(this.direction === Direction.Positive && this.options.bounces[1])
? this.wrapperSize
: 0
momentumInfo = this.hasScroll
? this.momentum(
this.currentPos,
this.startPos,
duration,
this.maxScrollPos,
this.minScrollPos,
wrapperSize,
this.options
)
: { destination: this.currentPos, duration: 0 }
} else {
private _checkPullDown() {
if (!this.scroll.options.pullDownRefresh) {
return
}
const { threshold = 90, stop = 40 } = this.scroll.options
.pullDownRefresh as PullDownRefreshConfig
// check if a real pull down action
if (
this.scroll.directionY !== Direction.Negative ||
this.scroll.y < threshold
) {
return false
}
if (!this.pulling) {
this.pulling = true
this.scroll.trigger('pullingDown')
this.originalMinScrollY = this.scroll.minScrollY
this.scroll.minScrollY = stop
}
this.scroll.scrollTo(
this.scroll.x,
stop,
break
}
wheelDeltaX *= direction
wheelDeltaY *= direction
if (!this.scroll.scroller.scrollBehaviorY.hasScroll) {
wheelDeltaX = wheelDeltaY
wheelDeltaY = 0
}
if (!this.scroll.scroller.scrollBehaviorX.hasScroll) {
wheelDeltaX = 0
}
const directionX =
wheelDeltaX > 0
? Direction.Negative
: wheelDeltaX < 0
? Direction.Positive
: 0
const directionY =
wheelDeltaY > 0
? Direction.Negative
: wheelDeltaY < 0
? Direction.Positive
: 0
return {
x: wheelDeltaX,
y: wheelDeltaY,
directionX,
directionY
}
}
updateDirection() {
const absDist = Math.round(this.currentPos) - this.absStartPos
this.direction =
absDist > 0
? Direction.Negative
: absDist < 0
? Direction.Positive
: Direction.Default
}
wheelDeltaX = wheelDeltaY
wheelDeltaY = 0
}
if (!this.scroll.scroller.scrollBehaviorX.hasScroll) {
wheelDeltaX = 0
}
const directionX =
wheelDeltaX > 0
? Direction.Negative
: wheelDeltaX < 0
? Direction.Positive
: 0
const directionY =
wheelDeltaY > 0
? Direction.Negative
: wheelDeltaY < 0
? Direction.Positive
: 0
return {
x: wheelDeltaX,
y: wheelDeltaY,
directionX,
directionY
}
}
private beforeHandler(e: CompatibleWheelEvent) {