vuescroll

repository·dev·Indexed 22 days ago

https://github.com/yvescoding/vuescroll

A customizable, multi-mode scrollbar plugin for Vue.js (v5.1.1) featuring support for native and slide modes, pull-to-refresh, push-to-load, and carousels. It provides a comprehensive API for programmatic scrolling via scrollTo(), scrollBy(), and scrollIntoView(), along with detailed configuration options for the scroll panel, rail, bar, and scroller physics.

Tokens
3.6K
Snippets
13
Records
20
Agent score
79%

What's inside vuescroll

  1. Configuration constraints for slide mode

    dev

    When configuring vuescroll in slide mode, you cannot enable certain features simultaneously.

    Constraint: You can only have one of the following enabled at a time:

    1. paging
    2. snapping (where snapping.enable is true)
    3. pullRefresh or pushLoad (where enable is true)

    If you attempt to enable more than one of these groups, the configValidator will trigger an error: paging, snapping, (pullRefresh with pushLoad) can only one of them to be true.

  2. Install and register the vueScroll component

    dev
    To use vueScroll in your Vue application, use the install method provided by the plugin. You can pass global configuration options via the ops property during installation. This will register the component globally and set $vuescrollConfig on Vue.config.globalProperties.
  3. Use the `scroll-container` slot for custom containers

    dev
    By default, vueScroll wraps your content in a managed div. If you need to use a custom element as the scroll container, you can use the scroll-container slot. When this slot is used, the plugin will inject its managed children and styles into your provided container.
  4. Configure the slide mode for vuescroll

    dev

    When using the slide mode in vuescroll, you can provide a configuration object to control rendering, refresh/load behaviors, paging, snapping, and scroller physics.

    Configuration Options

    vuescroll root object

    • renderMethod: Determines how the content is moved. Options are 'transform' or 'position'.
    • paging: Boolean. Enables paging mode.
    • zooming: Boolean. Enables zooming capabilities.
    • snapping: Object. Controls snapping behavior.
      • enable: Boolean.
      • width: Number.
      • height: Number.

    pullRefresh (Slide mode only)

    Enables pull-to-refresh functionality.

    • enable: Boolean.
    • tips: Object containing text strings for different states:
      • deactive: Text shown when idle (e.g., 'Pull to Refresh').
      • active: Text shown when pulling (e.g., 'Release to Refresh').
      • start: Text shown during the refresh process (e.g., 'Refreshing...').
      • beforeDeactive: Text shown when refresh completes (e.g., 'Refresh Successfully!').

    pushLoad (Slide mode only)

    Enables push-to-load functionality.

    • enable: Boolean.
    • auto: Boolean. If true, triggers loading automatically.
    • autoLoadDistance: Number. Distance threshold for auto-loading.
    • tips: Object containing text strings:
      • deactive: Text shown when idle (e.g., 'Push to Load').
      • active: Text shown when pushing (e.g., 'Release to Load').
      • start: Text shown during loading (e.g., 'Loading...').
      • beforeDeactive: Text shown when loading completes (e.g., 'Load Successfully!').

    scroller options

    Fine-grained control over scrolling physics and behavior:

    • bouncing: Object defining boundary bounce limits for top, bottom, left, and right.
    • minZoom: Number. Minimum zoom level.
    • maxZoom: Number. Maximum zoom level.
    • speedMultiplier: Number. Multiplier for scrolling speed.
    • penetrationDeceleration: Number. Change applied to deceleration at boundaries.
    • penetrationAcceleration: Number. Change applied to acceleration at boundaries.
    • preventDefault: Boolean. Whether to call e.preventDefault() during sliding.
    • preventDefaultOnMove: Boolean. Whether to call preventDefault() on move events.
    • disable: Boolean. Disables scroller features.
    {
      vuescroll: {
        renderMethod: 'transform',
        pullRefresh: {
          enable: false,
          tips: {
            deactive: 'Pull to Refresh',
            active: 'Release to Refresh',
            start: 'Refreshing...',
            beforeDeactive: 'Refresh Successfully!'
          }
        },
        pushLoad: {
          enable: false,
          tips: {
            deactive: 'Push to Load',
            active: 'Release to Load',
            start: 'Loading...',
            beforeDeactive: 'Load Successfully!'
          },
          auto: false,
          autoLoadDistance: 0
        },
        paging: false,
        zooming: true,
        snapping: {
          enable: false,
          width: 100,
          height: 100
        },
        scroller: {
          bouncing: {
            top: 100,
            bottom: 100,
            left: 100,
            right: 100
          },
          minZoom: 0.5,
          maxZoom: 3,
          speedMultiplier: 1,
          penetrationDeceleration: 0.03,
          penetrationAcceleration: 0.08,
          preventDefault: false,
          preventDefaultOnMove: true,
          disable: false
        }
      }
    }
  5. Configure the vuescroll mode

    dev

    When initializing vuescroll, you can specify a mode within the vuescroll configuration object. The available modes are determined by the library's internal modes list. If an invalid mode is provided, the validator will trigger an error indicating that the mode option must be one of the supported modes.

    const config = {
      vuescroll: {
        mode: 'native'
      }
    };
  6. Configure bar options

    dev

    The bar configuration defines the appearance and behavior of the scroll bar:

    • showDelay: How long to hide the bar after mouseleave. Defaults to 500.
    • specifyBorderRadius: If true, uses a specific border-radius; otherwise, it matches the rail's size. Defaults to false.
    • onlyShowBarOnScroll: Whether to show the bar only during scrolling. Defaults to true.
    • keepShow: Whether to keep the bar visible. Defaults to false.
    • background: The background color of the bar. Defaults to 'rgb(3, 185, 118)'.
    • opacity: The opacity of the bar. Defaults to 1.
    • size: The height/width of the bar. Defaults to '6px'.
    • minSize: The minimum size of the bar.
    • disable: Whether the bar is disabled. Defaults to false.
    const config = {
      bar: {
        showDelay: 500,
        specifyBorderRadius: false,
        onlyShowBarOnScroll: true,
        keepShow: false,
        background: 'rgb(3, 185, 118)',
        opacity: 1,
        size: '6px',
        minSize: 0,
        disable: false
      }
    };
  7. Configure scrollButton options

    dev

    The scrollButton configuration controls the behavior of scroll buttons:

    • enable: Whether scroll buttons are enabled. Defaults to false.
    • background: The background color of the button.
    • opacity: The opacity of the button.
    • step: The scroll step distance. Defaults to 180.
    • mousedownStep: The scroll step distance during mousedown. Defaults to 30.
    const config = {
      scrollButton: {
        enable: false,
        background: 'rgb(3, 185, 118)',
        opacity: 1,
        step: 180,
        mousedownStep: 30
      }
    };
  8. Configure vueScroll via the `ops` prop

    dev

    The vueScroll component accepts an ops prop of type Object. This allows you to provide component-specific configuration that overrides or merges with the global configuration. The configuration is organized into several namespaces:

    • vuescroll: Core settings (e.g., pullRefresh, pushLoad, scroller).
    • scrollPanel: Settings for the scrollable panel (e.g., maxHeight, maxWidth, initialScrollY, initialScrollX).
    • scrollContent: Settings for the content inside the scroll area.
    • rail: Settings for the scroll rail.
    • bar: Settings for the scrollbars (e.g., opacity, showDelay, keepShow).
  9. Configure rail options

    dev

    The rail configuration defines the appearance and behavior of the scroll rail:

    • background: The background color of the rail.
    • opacity: The opacity of the rail.
    • border: The border style.
    • size: The height/width of the rail. Defaults to '6px'.
    • specifyBorderRadius: If true, uses a specific border-radius; otherwise, it matches the rail's size. Defaults to false.
    • gutterOfEnds: Distance from the ends of the X/Y axes.
    • gutterOfSide: Distance from the side of the container. Defaults to '2px'.
    • keepShow: Whether to keep the rail visible even if content height is insufficient. Defaults to false.
    const config = {
      rail: {
        background: '#01a99a',
        opacity: 0,
        border: 'none',
        size: '6px',
        specifyBorderRadius: false,
        gutterOfEnds: null,
        gutterOfSide: '2px',
        keepShow: false
      }
    };
  10. Configure scrollPanel options

    dev

    The scrollPanel configuration controls the scrolling behavior and initial state of the panel:

    • initialScrollY / initialScrollX: Determines the starting scroll position. Must be a percentage string (e.g., '10%') or a number $\ge 0$ (e.g., 100).
    • scrollingX: Enables horizontal scrolling. Defaults to true.
    • scrollingY: Enables vertical scrolling. Defaults to true.
    • speed: The scroll speed in milliseconds. Defaults to 300.
    • easing: The easing function for the scroll animation.
    • verticalNativeBarPos: Sets the position of the native vertical scrollbar. Defaults to 'right'.
    • maxHeight / maxWidth: Constraints for the scroll panel.
    const config = {
      scrollPanel: {
        initialScrollY: '10%',
        initialScrollX: false,
        scrollingX: true,
        scrollingY: true,
        speed: 300,
        verticalNativeBarPos: 'right'
      }
    };
  11. Configure vuescroll options

    dev

    The vuescroll configuration object allows you to control the core behavior of the library. Key options include:

    • sizeStrategy: Determines how the size (height/width) is calculated. Options include 'percent' (e.g., '100%').
    • detectResize: A boolean indicating whether to detect DOM resizing. Defaults to true.
    • locking: A boolean that enables locking to the main axis if the user moves only slightly on one axis at the start. Defaults to true.
    const config = {
      vuescroll: {
        sizeStrategy: 'percent',
        detectResize: true,
        locking: true
      }
    };