2.1.2 • Published 1 year ago

@howdyjs/scroll v2.1.2

Weekly downloads
83
License
ISC
Repository
github
Last release
1 year ago

Scroll

Version Size

自定义滚动条插件

特性

  1. 通过配置项生成自定义样式的滚动条
  2. 支持拖拽滚动
  3. 基本不需要更改DOM布局,只需在overflow:scroll的元素上增加该指令即可
  4. 移动端中无效,会自动改回默认的滚动
  5. 封装了vue指令的形式
  6. 使用ResizeObserver监听盒子大小变化,已无需手动调用update方法(^2.1.2)

原生使用

import CustomScrollBar from '@howdyjs/scroll'
const scroll = new CustomScrollBar({
  el: '#scroll', // Selector or Dom
  options: {
    // Your Options
    // 参考下方说明
  }
});
scroll.init();
  • UMD CDN: https://unpkg.com/@howdyjs/scroll/dist/index.umd.js
  • UMD Name: HowdyScroll

Options (Objcet)

参数说明类型可选值默认值
direction滚动条方向Stringx/y/ally
scrollBarWidth滚动条宽度(轨道)Number-6
scrollBarOffsetX滚动条水平偏移(padding)Number-0
scrollBarOffsetY滚动条垂直偏移(padding)Number-0
scrollBarThumbColor滚动条滑块颜色String-#aab
scrollBarThumbBorderRadius滚动条滑块是否需要圆角Boolean-true
scrollBarThumbBorderRadius滚动条轨道颜色String-transparent
scrollBarThumbHoverColor滚动条滑块Hover时的颜色(默认不设置)String--
enableTrackClickScroll是否允许点击轨道进行滚动Boolean-true
scrollSpeed点击轨道时的滚动速度(滚动效果使用requestAnimationFrame实现,该值表示每帧的位移量,单位PX)Number-20
dragScroll是否开启拖拽滚动Boolean-false
thumbShow滚动条滑块显示方式,可选一直显示与Hover显示Stringalways/hoveralways
observeAutoUpdate自动更新滚动条,默认开启,若关闭则需要自行在盒子大小改变时手动调用更新方法Boolean-true

长度属性的单位为px

以Vue指令方式使用

import { ScrollDirective } from '@howdyjs/scroll'
// Vue3全局引入
app.use(ScrollDirective, someGlobalOptions)

// Vue2全局引入(对vue2做了兼容)
Vue.use(ScrollDirective, someGlobalOptions)

// 组件内引入
export default {
  directive: {
    scroll: ScrollDirective
  }
}

指令Arg

  1. y(默认), 开启垂直滚动
  2. x, 开启水平滚动
  3. all, 同时开启垂直、水平滚动

v-scroll:y | v-scroll:x | v-scroll:all

指令Value (Objcet)

参数同上方的配置Options

2.1.2

1 year ago

2.1.1

2 years ago

2.1.0

2 years ago

2.0.0

4 years ago

1.6.0

4 years ago

1.3.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago