Skip to content

Commit 320af61

Browse files
authored
Merge pull request #4 from HJ29/feature/2-wheel-speed
#2 wheel speed
2 parents 868257f + 74c53f6 commit 320af61

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export default defineComponent({
9393
| inactive-style | string | no | '' | css (change inactive option style)style |
9494
| active-class | string | no | '' | css class |
9595
| inactive-class | string | no | '' | css class |
96+
| wheel-speed | number | no | 1 | adjust mouse wheel speed with this value.<br>lower wheel speed, slower scroller |
9697

9798
### Event
9899
| Name | Description |

example/src/examples/Basic.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
<template>
22
<h3>Basic Example</h3 >
33
<scroll-picker
4+
:wheel-speed="wheelSpeed"
45
:options="options"
56
v-model="selections" />
67
<div style="margin-top: 30px;">
78
{{ selections }}
89
</div>
10+
<div style="padding-top: 30px;">
11+
<span style="font-size: 14px; padding-right: 10px;">Wheel Speed:</span>
12+
<input v-model="wheelSpeed">
13+
</div>
914
<button style="margin-top: 30px;" @click="onClickRandom">
1015
Random
1116
</button>
@@ -64,17 +69,13 @@ interface Option {
6469
value: string;
6570
}
6671
67-
interface State {
68-
options: Option[][];
69-
selections: (string | null)[];
70-
}
71-
7272
export default defineComponent({
7373
name: 'Basic',
7474
setup() {
75-
const state = reactive<State>({
75+
const state = reactive({
7676
options: mockOptions,
77-
selections: [],
77+
selections: [] as string[],
78+
wheelSpeed: 1
7879
});
7980
function random(number: number) {
8081
return Math.floor(Math.random() * number);
@@ -83,7 +84,6 @@ export default defineComponent({
8384
return typeof option === "string" ? option : option.value;
8485
}
8586
function onClickRandom() {
86-
state.selections
8787
state.selections = state.options.map(option => {
8888
return getValue(option[random(option.length)]);
8989
})

example/src/examples/Custom.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<h3>Custom Example</h3 >
33
<scroll-picker
4+
:wheel-speed="wheelSpeed"
45
style="background: white; height: 200px;"
56
:options="options"
67
v-model="selections"
@@ -24,6 +25,10 @@
2425
<div style="margin-top: 30px;">
2526
{{ selections }}
2627
</div>
28+
<div style="padding-top: 30px;">
29+
<span style="font-size: 14px; padding-right: 10px;">Wheel Speed:</span>
30+
<input v-model="wheelSpeed">
31+
</div>
2732
<button style="margin-top: 30px;" @click="onClickRandom">
2833
Random
2934
</button>
@@ -83,11 +88,12 @@ export default defineComponent({
8388
const state = reactive({
8489
options: mockOptions,
8590
selections: ['a2','b2','c1'],
91+
wheelSpeed: 1
8692
});
8793
function random(number: number) {
8894
return Math.floor(Math.random() * number);
8995
}
90-
function getValue(option) {
96+
function getValue(option: any) {
9197
return typeof option === "string" ? option : option.value;
9298
}
9399
function onClickRandom() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue3-scroll-picker",
3-
"version": "0.1.14",
3+
"version": "0.1.15",
44
"private": false,
55
"description": "Vue 3 scroll picker plugin.",
66
"author": "hj <[email protected]>",

src/ScrollPicker.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ export default defineComponent({
131131
inactiveStyle: {
132132
default: "",
133133
type: String
134+
},
135+
wheelSpeed: {
136+
default: 1,
137+
type: Number
134138
}
135139
},
136140
emits: ["update:modelValue"],
@@ -263,7 +267,7 @@ export default defineComponent({
263267
preventDefault(event);
264268
const content = getContent(event);
265269
if (content) {
266-
content.scrollTop += (event as WheelEvent).deltaY;
270+
content.scrollTop += (event as WheelEvent).deltaY * props.wheelSpeed;
267271
const { columnIndex, rowIndex } = getColumnRowIndex(content);
268272
const newSelections = getSelections(columnIndex, rowIndex);
269273
setSelections(newSelections);

0 commit comments

Comments
 (0)