Skip to content

Commit cf21d83

Browse files
committed
update README.md
1 parent d057315 commit cf21d83

File tree

9 files changed

+43
-39
lines changed

9 files changed

+43
-39
lines changed

README-zh_CN.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
custom-vue-scrollbar(Vue3)
22
=========================
33

4-
[custom-react-scrollbar(react版)](https://github.com/custom-lib/custom-react-scrollbar)
4+
[custom-react-scrollbar (react版)](https://github.com/custom-lib/custom-react-scrollbar)
55

66
中文 | [English](https://github.com/custom-lib/custom-vue-scrollbar/blob/main/READM.md)
77

@@ -20,6 +20,7 @@ custom-vue-scrollbar(Vue3)
2020
* typescript支持
2121

2222
## 引入
23+
2324
```bash
2425
npm install --save custom-vue-scrollbar
2526
```
@@ -44,7 +45,9 @@ declare module 'vue' {
4445
```javascript
4546
<template>
4647
<custom-scrollbar :style="{ width: '500px', height: '300px' }">
47-
<p>Some great content...</p>
48+
<div :style="{ width: '1000px', height: '600px' }">
49+
Some great content...
50+
</div>
4851
</custom-scrollbar>
4952
</template>
5053
```
@@ -93,6 +96,7 @@ ResizeObserver监听 包裹/内容 容器的尺寸变化来更新滚动条的尺
9396
使用wheel模拟滚动代替原生滚动。在需要与外部浮动的元素同步滚动进度时开启,可以消除原生滚动在同步时 不在同一轮事件循环里 带来的抖动。
9497

9598
### Emit
99+
96100
```javascript
97101
interface Rect {
98102
left: number;
@@ -150,4 +154,5 @@ MIT
150154

151155

152156
## custom-lib相关QQ群
157+
153158
![image](https://github.com/custom-lib/custom-vue-scrollbar/blob/main/website/assets/qrCode.jpg)

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
custom-vue-scrollbar(Vue3)
22
=========================
33

4-
[react version here.](https://github.com/custom-lib/custom-react-scrollbar)
4+
[custom-react-scrollbar (react version here)](https://github.com/custom-lib/custom-react-scrollbar)
55

66
English | [中文](https://github.com/custom-lib/custom-vue-scrollbar/blob/main/README-zh_CN.md)
77

@@ -16,10 +16,11 @@ It's dependencies of custom-vue-table.
1616
* 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).
1717
* High performance.Optional debounce/throttle to observe size changes.。
1818
* 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).
19+
* it's lightweight. 16.5kb uncompressed, 4.5kb after compression (gzip).
2020
* typescript support.
2121

2222
## Install
23+
2324
```bash
2425
npm install --save custom-vue-scrollbar
2526
```
@@ -44,7 +45,9 @@ Just give it a fixed size like using a native scroll container.
4445
```javascript
4546
<template>
4647
<custom-scrollbar :style="{ width: '500px', height: '300px' }">
47-
<p>Some content...</p>
48+
<div :style="{ width: '1000px', height: '600px' }">
49+
Some great content...
50+
</div>
4851
</custom-scrollbar>
4952
</template>
5053
```
@@ -82,7 +85,7 @@ When the scrolling is triggered, the scrollbar will be hidden only after the del
8285
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.
8386

8487
**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.
88+
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 scrollbar of the secondary axis will float to the edge of the screen.
8689

8790
**throttleType** _`:'throttle' | 'debounce' | 'none'`_ = 'debounce'
8891
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.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "custom-vue-scrollbar",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"license": "MIT",
55
"module": "dist/index.js",
66
"types": "dist/index.d.ts",
@@ -20,13 +20,13 @@
2020
"devDependencies": {
2121
"@types/lodash-es": "^4.17.5",
2222
"@types/stats.js": "^0.17.0",
23-
"@vitejs/plugin-vue": "^1.9.2",
23+
"@vitejs/plugin-vue": "^1.9.3",
2424
"@vue/compiler-sfc": "^3.2.19",
2525
"rollup-plugin-visualizer": "^5.5.2",
2626
"sass": "^1.42.1",
2727
"stats.js": "^0.17.0",
2828
"typescript": "^4.4.3",
29-
"vite": "^2.6.2",
29+
"vite": "^2.6.3",
3030
"vue-i18n": "^9.2.0-beta.11"
3131
},
3232
"dependencies": {

src/useMeasure.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { debounce, throttle } from 'lodash-es';
2-
import { onUnmounted, reactive, shallowRef, watchEffect } from 'vue';
32
import type { Ref } from 'vue';
3+
import { onUnmounted, reactive, shallowRef, watchEffect } from 'vue';
44

55
export interface Rect {
66
left: number;
@@ -35,8 +35,23 @@ export default function useMeasure<T extends Element | SVGSVGElement = any>(...a
3535
const targetRef = hasParamRef ? args[0] : shallowRef<T>(null!)
3636
const rect = reactive<Rect>({ left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0 });
3737

38+
const observerFunc = () => {
39+
const domRect = targetRef.value.getBoundingClientRect();
40+
rect.left = domRect.left;
41+
rect.top = domRect.top;
42+
rect.right = domRect.right;
43+
rect.bottom = domRect.bottom;
44+
rect.width = domRect.width;
45+
rect.height = domRect.height;
46+
rect.x = domRect.x;
47+
rect.y = domRect.y;
48+
callback?.();
49+
};
50+
let execFunc: (() => void) | null = null;
51+
3852
let ro: ResizeObserver | null = null;
3953
const clearRo = () => {
54+
if (execFunc) window.removeEventListener('resize', execFunc);
4055
if (!ro) return;
4156
ro.disconnect();
4257
ro = null;
@@ -45,20 +60,8 @@ export default function useMeasure<T extends Element | SVGSVGElement = any>(...a
4560
watchEffect(() => {
4661
if (!targetRef.value) return;
4762
clearRo();
48-
const observerFunc = () => {
49-
const domRect = targetRef.value.getBoundingClientRect();
50-
rect.left = domRect.left;
51-
rect.top = domRect.top;
52-
rect.right = domRect.right;
53-
rect.bottom = domRect.bottom;
54-
rect.width = domRect.width;
55-
rect.height = domRect.height;
56-
rect.x = domRect.x;
57-
rect.y = domRect.y;
58-
callback?.();
59-
};
6063

61-
let execFunc = observerFunc;
64+
execFunc = observerFunc;
6265
if (type === 'throttle' && wait >= 4) execFunc = throttle(execFunc, wait);
6366
else if (type === 'debounce' && wait >= 4) execFunc = debounce(execFunc, wait);
6467
window.addEventListener('resize', execFunc);

website/Box.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<div class="box_desc">
1212
{{ desc }}
1313
</div>
14-
<div class="box_opertion">
15-
<slot name="opertion"></slot>
14+
<div class="box_operation">
15+
<slot name="operation"></slot>
1616
</div>
1717
<div class="box_content">
1818
<slot></slot>
@@ -102,7 +102,7 @@ defineProps<Props>();
102102
opacity: .7;
103103
}
104104
105-
.box_opertion {
105+
.box_operation {
106106
font-size: 18px;
107107
font-weight: 600;
108108
color: #31456A;

website/examples/AutoHeight.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:desc="$t('desc')"
55
codeSrc="https://github.com/custom-lib/custom-vue-scrollbar/blob/main/website/examples/AutoHeight.vue"
66
>
7-
<template #opertion>
7+
<template #operation>
88
<div class="operation">
99
<div class="operation_btn" @click="paragraphCount += 1">
1010
<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M942.6 383.8H640.1V81.3c0-44-36-80-80-80h-96.2c-44 0-80 36-80 80v302.5H81.4c-44 0-80 36-80 80V560c0 44 36 80 80 80h302.5v302.5c0 44 36 80 80 80h96.2c44 0 80-36 80-80V640.1h302.5c44 0 80-36 80-80v-96.2c0-44.1-36-80.1-80-80.1z" fill="#31456A"></path></svg>
@@ -16,7 +16,7 @@
1616
</template>
1717
<template #default>
1818
<custom-scrollbar :style="{ maxHeight: '40vh' }" :autoHide="false" throttleType="none">
19-
<div v-for="(_, index) in paragraphCount" :style="{ height: '8vh', lineHeight: '8vh' }">
19+
<div v-for="(_, index) in paragraphCount" :style="{ height: '8vh', lineHeight: '8vh' }" :key="index">
2020
{{ index }}:
2121
{{
2222
paragraphCount < 6 ? `Add ${6 - paragraphCount} more paragraph to show scroller.`

website/examples/FixedThumb.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export default defineComponent({
2323
desc: `
2424
The 'direction' property specifies the direction as the 'major axis direction'.
2525
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.
26-
The scrollbars of the secondary axis will float to the edge of the screen.
26+
The scrollbar of the secondary axis will float to the edge of the screen.
2727
`
2828
},
2929
zh: {
30-
title: '基础用法',
30+
title: '浮动滚动条',
3131
desc: `'direction' 属性 指定的方向为 '主轴方向'。开启 'fixedThumb' 属性 后,如果辅轴有滚动条,并且主轴方向有部分滚动容器位于屏幕外。辅轴的滚动条将会浮动至屏幕边缘。`
3232
},
3333
},

website/examples/ThumbSize.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:desc="$t('desc')"
55
codeSrc="https://github.com/custom-lib/custom-vue-scrollbar/blob/main/website/examples/ThumbSize.vue"
66
>
7-
<template #opertion>
7+
<template #operation>
88
<div class="operation">
99
<span :style="{ marginRight: '8px' }">thumbMinSize:</span> <input class="operation_input" type="number" v-model="thumbMinSize" />(px)
1010
</div>
@@ -47,13 +47,6 @@ let thumbMinSize = $ref(160);
4747
</script>
4848

4949
<style lang="scss">
50-
.operation {
51-
display: flex;
52-
justify-content: center;
53-
align-items: center;
54-
margin-bottom: 16px;
55-
}
56-
5750
.operation_input {
5851
all: unset;
5952
margin-right: 20px;

website/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ function animate() {
3535
requestAnimationFrame( animate );
3636
}
3737

38-
requestAnimationFrame( animate );
38+
requestAnimationFrame( animate );

0 commit comments

Comments
 (0)