How to use @better-scroll/core - 10 common examples

To help you get started, we’ve selected a few @better-scroll/core 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 / observe-dom / src / __tests__ / ObserveDom.spec.ts View on Github external
it('observe without MutationObserver', () => {
    const bs = createBS()
    const obDom = new ObserveDom(bs)

    jest.advanceTimersByTime(1000)
    expect(bs.refresh).not.toBeCalled()

    mockDomOffset(bs.scroller.content, {
      width: 400
    })
    jest.advanceTimersByTime(1000)
    expect(bs.refresh).toBeCalledTimes(1)
    // destroy
    bs.hooks.trigger('destroy')
    mockDomOffset(bs.scroller.content, {
      width: 500
    })
    jest.advanceTimersByTime(1000)
    expect(bs.refresh).toBeCalledTimes(1)
  })
github ustbhuangyi / better-scroll / packages / pull-up / src / __tests__ / index.spec.ts View on Github external
beforeAll(() => {
    // create DOM
    const wrapper = document.createElement('div')
    const content = document.createElement('div')
    wrapper.appendChild(content)
    // mock bscroll
    bscroll = new BScroll(wrapper, {})
    bscroll.maxScrollY = MAX_SCROLL_Y
    bscroll.movingDirectionY = MOVING_DIRECTION_Y
  })
github ustbhuangyi / better-scroll / packages / scroll-bar / src / __tests__ / index.spec.ts View on Github external
beforeAll(() => {
    // create Dom
    const wrapper = document.createElement('div')
    const content = document.createElement('div')
    wrapper.appendChild(content)
    // mock bscroll
    options = {
      scrollbar: CONFIG_SCROLL_BAR,
      scrollX: true,
      scrollY: true
    }
    bscroll = new BScroll(wrapper, options)
  })
github ustbhuangyi / better-scroll / packages / scroll-bar / src / __tests__ / indicator.spec.ts View on Github external
beforeEach(() => {
    // create Dom indicator
    const indicatorWrapper = document.createElement('div')
    const indicatorEl = document.createElement('div')
    indicatorWrapper.appendChild(indicatorEl)
    // mock clientHeight and clientWidth
    mockDomClient(indicatorWrapper, { height: 100, width: 100 })

    indicatorOptions = {
      wrapper: indicatorWrapper,
      direction: 'vertical' as Direction,
      fade: true,
      interactive: true
    }
  })
github ustbhuangyi / better-scroll / packages / mouse-wheel / src / index.ts View on Github external
registorEvent() {
    this.eventRegistor = new EventRegister(this.scroll.scroller.wrapper, [
      {
        name: 'wheel',
        handler: this.wheelHandler.bind(this)
      },
      {
        name: 'mousewheel',
        handler: this.wheelHandler.bind(this)
      },
      {
        name: 'DOMMouseScroll', // FireFox
        handler: this.wheelHandler.bind(this)
      }
    ])
  }
  wheelHandler(e: CompatibleWheelEvent) {
github ustbhuangyi / better-scroll / packages / nested-scroll / src / __tests__ / index.spec.ts View on Github external
it("should make childScroll'options.click false when both BScroll' options.click are true", () => {
    const parentScroll = new BScroll(parentWrapper, {
      click: true
    })
    const childScroll = new BScroll(childWrapper, {
      click: true
    })
    let nestedScroll1 = new NestedScroll(parentScroll)
    let nestedScroll2 = new NestedScroll(childScroll)

    expect(childScroll.options.click).toBe(false)
  })
})
github ustbhuangyi / better-scroll / packages / core / src / base / __tests__ / ActionsHandler.spec.ts View on Github external
it('should invoice move method when dispatch touchmove', () => {
    actionsHandler = new ActionsHandler(wrapper, options)
    const moveMockHandler = jest.fn().mockImplementation(() => {
      return 'dummy test'
    })

    actionsHandler.hooks.on('move', moveMockHandler)

    dispatchMouse(wrapper, 'mousedown')

    dispatchMouse(window, 'mousemove')

    expect(moveMockHandler).toBeCalled()
  })
github ustbhuangyi / better-scroll / packages / core / src / base / __tests__ / ActionsHandler.spec.ts View on Github external
it('should invoice end method when dispatch touchend', () => {
    actionsHandler = new ActionsHandler(wrapper, options)
    const endMockHandler = jest.fn().mockImplementation(() => {
      return 'dummy test'
    })

    actionsHandler.hooks.on('end', endMockHandler)

    dispatchMouse(wrapper, 'mousedown')

    dispatchMouse(window, 'mouseup')

    expect(endMockHandler).toBeCalled()
  })