How to use the @better-scroll/shared-utils.fixInboundValue 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 / mouse-wheel / src / index.ts View on Github external
y: prev.y + current.y
          }
        },
        { x: 0, y: 0 }
      )
      this.deltaCache = []
      let newX = this.scroll.x + Math.round(delta.x) + cachedDelta.x
      let newY = this.scroll.y + Math.round(delta.y) + cachedDelta.y
      const scrollBehaviorX = this.scroll.scroller.scrollBehaviorX
      const scrollBehaviorY = this.scroll.scroller.scrollBehaviorY
      newX = fixInboundValue(
        newX,
        scrollBehaviorX.maxScrollPos,
        scrollBehaviorX.minScrollPos
      )
      newY = fixInboundValue(
        newY,
        scrollBehaviorY.maxScrollPos,
        scrollBehaviorY.minScrollPos
      )

      if (
        !this.scroll.trigger(this.scroll.eventTypes.mousewheelMove, {
          x: newX,
          y: newY
        })
      ) {
        const easeTime = this.getEaseTime()
        if (newX !== this.scroll.x || newY !== this.scroll.y) {
          this.scroll.scrollTo(newX, newY, easeTime)
        }
      }
github ustbhuangyi / better-scroll / packages / mouse-wheel / src / index.ts View on Github external
} else {
      const cachedDelta = this.deltaCache.reduce(
        (prev, current) => {
          return {
            x: prev.x + current.x,
            y: prev.y + current.y
          }
        },
        { x: 0, y: 0 }
      )
      this.deltaCache = []
      let newX = this.scroll.x + Math.round(delta.x) + cachedDelta.x
      let newY = this.scroll.y + Math.round(delta.y) + cachedDelta.y
      const scrollBehaviorX = this.scroll.scroller.scrollBehaviorX
      const scrollBehaviorY = this.scroll.scroller.scrollBehaviorY
      newX = fixInboundValue(
        newX,
        scrollBehaviorX.maxScrollPos,
        scrollBehaviorX.minScrollPos
      )
      newY = fixInboundValue(
        newY,
        scrollBehaviorY.maxScrollPos,
        scrollBehaviorY.minScrollPos
      )

      if (
        !this.scroll.trigger(this.scroll.eventTypes.mousewheelMove, {
          x: newX,
          y: newY
        })
      ) {
github ustbhuangyi / better-scroll / packages / slide / src / SlidePage.ts View on Github external
}
    let lastX = this.pagesPos.xLen - 1
    let lastY = this.pagesPos.yLen - 1
    let firstX = 0
    let firstY = 0
    if (this.loopX) {
      x += 1
      firstX = firstX + 1
      lastX = lastX - 1
    }
    if (this.loopY) {
      y += 1
      firstY = firstY + 1
      lastY = lastY - 1
    }
    x = fixInboundValue(x, firstX, lastX)
    y = fixInboundValue(y, firstY, lastY)
    return {
      realX: x,
      realY: y
    }
  }
  nextPage(): { pageX: number; pageY: number } {
github ustbhuangyi / better-scroll / packages / slide / src / SlidePage.ts View on Github external
let lastX = this.pagesPos.xLen - 1
    let lastY = this.pagesPos.yLen - 1
    let firstX = 0
    let firstY = 0
    if (this.loopX) {
      x += 1
      firstX = firstX + 1
      lastX = lastX - 1
    }
    if (this.loopY) {
      y += 1
      firstY = firstY + 1
      lastY = lastY - 1
    }
    x = fixInboundValue(x, firstX, lastX)
    y = fixInboundValue(y, firstY, lastY)
    return {
      realX: x,
      realY: y
    }
  }
  nextPage(): { pageX: number; pageY: number } {
github ustbhuangyi / better-scroll / packages / slide / src / SlidePage.ts View on Github external
y: 0,
        pageX: 0,
        pageY: 0
      }
    }
    let pageX = pageInfo.pageX
    let pageY = pageInfo.pageY
    let newX
    let newY
    if (pageX === this.currentPage.pageX) {
      pageX += directionX
      pageX = fixInboundValue(pageX, 0, this.pagesPos.xLen - 1)
    }
    if (pageY === this.currentPage.pageY) {
      pageY += directionY
      pageY = fixInboundValue(pageInfo.pageY, 0, this.pagesPos.yLen - 1)
    }
    newX = this.pagesPos.getPos(pageX, 0).x
    newY = this.pagesPos.getPos(0, pageY).y
    return {
      x: newX,
      y: newY,
      pageX,
      pageY
    }
  }
  getLoopStage(): LoopStage {
github ustbhuangyi / better-scroll / packages / slide / src / SlidePage.ts View on Github external
const pageInfo = this.pagesPos.getNearestPage(x, y)
    if (!pageInfo) {
      return {
        x: 0,
        y: 0,
        pageX: 0,
        pageY: 0
      }
    }
    let pageX = pageInfo.pageX
    let pageY = pageInfo.pageY
    let newX
    let newY
    if (pageX === this.currentPage.pageX) {
      pageX += directionX
      pageX = fixInboundValue(pageX, 0, this.pagesPos.xLen - 1)
    }
    if (pageY === this.currentPage.pageY) {
      pageY += directionY
      pageY = fixInboundValue(pageInfo.pageY, 0, this.pagesPos.yLen - 1)
    }
    newX = this.pagesPos.getPos(pageX, 0).x
    newY = this.pagesPos.getPos(0, pageY).y
    return {
      x: newX,
      y: newY,
      pageX,
      pageY
    }
  }
  getLoopStage(): LoopStage {