Skip to content

#2 wheel speed #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export default defineComponent({
| inactive-style | string | no | '' | css (change inactive option style)style |
| active-class | string | no | '' | css class |
| inactive-class | string | no | '' | css class |
| wheel-speed | number | no | 1 | adjust mouse wheel speed with this value.<br>lower wheel speed, slower scroller |

### Event
| Name | Description |
Expand Down
16 changes: 8 additions & 8 deletions example/src/examples/Basic.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<template>
<h3>Basic Example</h3 >
<scroll-picker
:wheel-speed="wheelSpeed"
:options="options"
v-model="selections" />
<div style="margin-top: 30px;">
{{ selections }}
</div>
<div style="padding-top: 30px;">
<span style="font-size: 14px; padding-right: 10px;">Wheel Speed:</span>
<input v-model="wheelSpeed">
</div>
<button style="margin-top: 30px;" @click="onClickRandom">
Random
</button>
Expand Down Expand Up @@ -64,17 +69,13 @@ interface Option {
value: string;
}

interface State {
options: Option[][];
selections: (string | null)[];
}

export default defineComponent({
name: 'Basic',
setup() {
const state = reactive<State>({
const state = reactive({
options: mockOptions,
selections: [],
selections: [] as string[],
wheelSpeed: 1
});
function random(number: number) {
return Math.floor(Math.random() * number);
Expand All @@ -83,7 +84,6 @@ export default defineComponent({
return typeof option === "string" ? option : option.value;
}
function onClickRandom() {
state.selections
state.selections = state.options.map(option => {
return getValue(option[random(option.length)]);
})
Expand Down
8 changes: 7 additions & 1 deletion example/src/examples/Custom.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<template>
<h3>Custom Example</h3 >
<scroll-picker
:wheel-speed="wheelSpeed"
style="background: white; height: 200px;"
:options="options"
v-model="selections"
Expand All @@ -24,6 +25,10 @@
<div style="margin-top: 30px;">
{{ selections }}
</div>
<div style="padding-top: 30px;">
<span style="font-size: 14px; padding-right: 10px;">Wheel Speed:</span>
<input v-model="wheelSpeed">
</div>
<button style="margin-top: 30px;" @click="onClickRandom">
Random
</button>
Expand Down Expand Up @@ -83,11 +88,12 @@ export default defineComponent({
const state = reactive({
options: mockOptions,
selections: ['a2','b2','c1'],
wheelSpeed: 1
});
function random(number: number) {
return Math.floor(Math.random() * number);
}
function getValue(option) {
function getValue(option: any) {
return typeof option === "string" ? option : option.value;
}
function onClickRandom() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue3-scroll-picker",
"version": "0.1.14",
"version": "0.1.15",
"private": false,
"description": "Vue 3 scroll picker plugin.",
"author": "hj <[email protected]>",
Expand Down
6 changes: 5 additions & 1 deletion src/ScrollPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export default defineComponent({
inactiveStyle: {
default: "",
type: String
},
wheelSpeed: {
default: 1,
type: Number
}
},
emits: ["update:modelValue"],
Expand Down Expand Up @@ -263,7 +267,7 @@ export default defineComponent({
preventDefault(event);
const content = getContent(event);
if (content) {
content.scrollTop += (event as WheelEvent).deltaY;
content.scrollTop += (event as WheelEvent).deltaY * props.wheelSpeed;
const { columnIndex, rowIndex } = getColumnRowIndex(content);
const newSelections = getSelections(columnIndex, rowIndex);
setSelections(newSelections);
Expand Down