|
| 1 | +custom-vue-scrollbar(Vue3) |
| 2 | +========================= |
| 3 | + |
| 4 | +[react version here.](https://github.com/custom-lib/custom-react-scrollbar) |
| 5 | + |
| 6 | +English | [中文](https://github.com/custom-lib/custom-vue-scrollbar/blob/main/README-zh_CN.md) |
| 7 | + |
| 8 | +**[Demos](https://custom-lib.github.io/custom-vue-scrollbar/)** |
| 9 | + |
| 10 | +It's dependencies of custom-vue-table. |
| 11 | + |
| 12 | +* Few APIs, used like native scroll container. |
| 13 | +* Customize the scroll bar style. |
| 14 | +* Support the minimum size/maximum size setting of the scroll bar. |
| 15 | +* Automatically hide the scroll bar and optional set the automatic hide delay. |
| 16 | +* Floating scroll bar (when the scroll container exceeds the visible area of the screen, the scroll bar is fixed at the bottom of the screen). |
| 17 | +* High performance.Optional debounce/throttle to observe size changes.。 |
| 18 | +* Support native scroll mode (default) and simulate scroll mode (useful in scenes such as: scroll synchronously with outer float elements). |
| 19 | +* it's lightweight.16.5kb uncompressed, 4.5kb after compression (gzip). |
| 20 | +* typescript support. |
| 21 | + |
| 22 | +## Install |
| 23 | +```bash |
| 24 | +npm install --save custom-vue-scrollbar |
| 25 | +``` |
| 26 | + |
| 27 | +```javascript |
| 28 | +// main.ts |
| 29 | +import CustomScrollbar from 'custom-vue-scrollbar'; |
| 30 | +import 'custom-vue-scrollbar/dist/style.css'; |
| 31 | +app.component(CustomScrollbar.name, CustomScrollbar); |
| 32 | + |
| 33 | +declare module 'vue' { |
| 34 | + export interface GlobalComponents { |
| 35 | + CustomScrollbar: typeof CustomScrollbar; |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Basic Usage |
| 41 | + |
| 42 | +Just give it a fixed size like using a native scroll container. |
| 43 | + |
| 44 | +```javascript |
| 45 | +<template> |
| 46 | + <custom-scrollbar :style="{ width: '500px', height: '300px' }"> |
| 47 | + <p>Some content...</p> |
| 48 | + </custom-scrollbar> |
| 49 | +</template> |
| 50 | +``` |
| 51 | + |
| 52 | + |
| 53 | +### Props |
| 54 | + |
| 55 | +In addition to the following component Props, all native DOM properties and events can also be used. |
| 56 | + |
| 57 | +**class** _`:string`_ = undefined |
| 58 | +Container class, which is generally only used to set the size. |
| 59 | + |
| 60 | +**style** _`:object`_ = undefined |
| 61 | +Container style. |
| 62 | + |
| 63 | +**contentClass** _`:string`_ = undefined |
| 64 | +Content class, the place to set display, padding, etc. |
| 65 | + |
| 66 | +**contentStyle** _`:object`_ = undefined |
| 67 | +Content style. |
| 68 | + |
| 69 | +**direction** _`:'horizontal' | 'vertical'`_ = 'vertical' |
| 70 | +If you need to change the content container to horizontal layout, you can set the component property 'direction' to 'horizontal' to change the layout to 'display': 'flex' & 'flex-direction': 'row'. Or set it manually via 'contentClass' / 'contentStyle' properties. However, it is not recommended to set it manually, as the 'direction' property is related to the 'fixedThumb' property below. |
| 71 | + |
| 72 | +**thumbMinSize / thumbMaxSize** _`:number`_ = 48 / Infinity |
| 73 | +Sets the minimum/maximum size of the scrollbar. |
| 74 | + |
| 75 | +**autoHide** _`:boolean`_ = true |
| 76 | +When turned on, the scrollbar will be displayed only when the mouse hovers over the scroll container. |
| 77 | + |
| 78 | +**autoHideDelay** _`:number(ms)`_ = 900 |
| 79 | +When the scrolling is triggered, the scrollbar will be hidden only after the delay set by autoHideDelay. |
| 80 | + |
| 81 | +**autoExpand** _`:boolean`_ = true |
| 82 | +Scroll bar default is 8px wide, the actual external has a 12px placeholder container, click, drag and drop logic is hanging on this placeholder container (convenient to click, 8px visually comfortable but difficult). When this option is turned on, the occupancy container hover, the scrollbar width will change to the width of the occupancy container. |
| 83 | + |
| 84 | +**fixedThumb** _`:boolean`_ = false |
| 85 | +The 'direction' property specifies the direction as the 'major axis direction'. When the 'fixedThumb' property is turned on, if the secondary axis has a scrollbar and the major axis has a scroll container that is partially off-screen. The scrollbars of the secondary axis will float to the edge of the screen. |
| 86 | + |
| 87 | +**throttleType** _`:'throttle' | 'debounce' | 'none'`_ = 'debounce' |
| 88 | +ResizeObserver listens for changes in the size of the container/content DOM Node to update the size of the scrollbar. Most scenarios do not require a high refresh rate and using 'debounce' is sufficient in most scenarios. |
| 89 | + |
| 90 | +**throttleWait** _`:number`_ = 333 |
| 91 | +The time to trigger when the 'throttleType' attribute is not 'none'. |
| 92 | + |
| 93 | +**simulateScroll** _`:boolean`_ = false |
| 94 | +Use 'wheel' to simulate scrolling instead of native scrolling. Turn it on when you need to synchronize the scrolling progress with an external floating element to eliminate the jitter caused by native scrolling that is not in the same event loop when synchronizing. |
| 95 | + |
| 96 | +### Emit |
| 97 | + |
| 98 | +```javascript |
| 99 | +interface Rect { |
| 100 | + left: number; |
| 101 | + top: number; |
| 102 | + right: number; |
| 103 | + bottom: number; |
| 104 | + width: number; |
| 105 | + height: number; |
| 106 | + x: number; |
| 107 | + y: number; |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +**wrapperResize** _`:(rect: Rect) => void`_ |
| 112 | +Triggered when the size of the scroller container changes |
| 113 | + |
| 114 | +**contentResize** _`:(rect: Rect) => void`_ |
| 115 | +Triggered when the size of the scroller content changes |
| 116 | + |
| 117 | +### Overwrite scrollbar style |
| 118 | + |
| 119 | +```javascript |
| 120 | +// Modify the scrollbar size (placeholder container), the width of the scrollbar display before hover is 2/3 of the placeholder container, as follows, it is 12px. |
| 121 | +.scrollbar__thumbPlaceholder--vertical { |
| 122 | + width: 20px; |
| 123 | +} |
| 124 | +.scrollbar__thumbPlaceholder--horizontal { |
| 125 | + height: 20px; |
| 126 | +} |
| 127 | + |
| 128 | +// Modify the scrollbar style. |
| 129 | +.scrollbar__thumb { |
| 130 | + background-color: red; |
| 131 | +} |
| 132 | +``` |
| 133 | + |
| 134 | +## Running example |
| 135 | + |
| 136 | +Run the demos: |
| 137 | +```bash |
| 138 | +npm install |
| 139 | +npm run dev |
| 140 | +``` |
| 141 | + |
| 142 | +## Build lib |
| 143 | +```bash |
| 144 | +npm install |
| 145 | +npm run build:lib |
| 146 | +``` |
| 147 | + |
| 148 | +## License |
| 149 | + |
| 150 | +MIT |
0 commit comments