How to use the @better-scroll/shared-utils.Direction.Positive function in @better-scroll/shared-utils

To help you get started, we’ve selected a few @better-scroll/shared-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ustbhuangyi / better-scroll / packages / pull-up / src / index.ts View on Github external
private _checkToEnd(pos: { y: number }) {
    if (!this.bscroll.options.pullUpLoad) {
      return
    }

    const { threshold = 0 } = this.bscroll.options
      .pullUpLoad as PullUpLoadConfig
    if (
      this.bscroll.movingDirectionY === Direction.Positive &&
      pos.y <= this.bscroll.maxScrollY + threshold
    ) {
      // reset pullupWatching status after scroll end to promise that trigger 'pullingUp' only once when pulling up
      this.bscroll.once('scrollEnd', () => {
        this.watching = false
      })
      this.bscroll.trigger('pullingUp')
      this.bscroll.off('scroll', this._checkToEnd)
    }
  }
github ustbhuangyi / better-scroll / packages / core / src / scroller / Behavior.ts View on Github external
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 {
      this.hooks.trigger(this.hooks.eventTypes.end, momentumInfo)
github ustbhuangyi / better-scroll / packages / core / src / scroller / Behavior.ts View on Github external
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
      }
    }
github ustbhuangyi / better-scroll / packages / mouse-wheel / src / index.ts View on Github external
private getWheelDelta(e: CompatibleWheelEvent) {
    const { speed = 20, invert = false } = this.mouseWheelOpt
    let wheelDeltaX = 0
    let wheelDeltaY = 0
    let direction = invert ? Direction.Negative : Direction.Positive
    switch (true) {
      case 'deltaX' in e:
        if (e.deltaMode === 1) {
          wheelDeltaX = -e.deltaX * speed
          wheelDeltaY = -e.deltaY * speed
        } else {
          wheelDeltaX = -e.deltaX
          wheelDeltaY = -e.deltaY
        }
        break
      case 'wheelDeltaX' in e:
        wheelDeltaX = (e.wheelDeltaX / 120) * speed
        wheelDeltaY = (e.wheelDeltaY / 120) * speed
        break
      case 'wheelDelta' in e:
        wheelDeltaX = wheelDeltaY = (e.wheelDelta / 120) * speed
github ustbhuangyi / better-scroll / packages / mouse-wheel / src / index.ts View on Github external
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
    }
  }
  private beforeHandler(e: CompatibleWheelEvent) {
github ustbhuangyi / better-scroll / packages / mouse-wheel / src / index.ts View on Github external
}
    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) {
github ustbhuangyi / better-scroll / packages / core / src / scroller / Behavior.ts View on Github external
updateDirection() {
    const absDist = Math.round(this.currentPos) - this.absStartPos
    this.direction =
      absDist > 0
        ? Direction.Negative
        : absDist < 0
        ? Direction.Positive
        : Direction.Default
  }