Skip to content
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

style(image-viewer): adjust the default zoom ratio of the image #4583

Merged
merged 4 commits into from
Sep 23, 2024
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
14 changes: 9 additions & 5 deletions src/image-viewer/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { positiveSubtract, positiveAdd } from '../_common/js/input-number/number';
import { ref, watch } from 'vue';
import { ImageScale } from './type';
import throttle from 'lodash/throttle';

interface InitTransform {
translateX: number;
Expand Down Expand Up @@ -48,17 +49,20 @@ export function useMirror() {
return { mirror, onMirror, resetMirror };
}

export function useScale(imageScale: ImageScale = { max: 2, min: 0.5, step: 0.5 }) {
export function useScale(imageScale: ImageScale = { max: 2, min: 0.5, step: 0.2 }) {
const { max, min, step, defaultScale } = imageScale;
const scale = ref(defaultScale ?? 1);
const onZoomIn = () => {

const onZoomIn = throttle(() => {
const result = positiveAdd(scale.value, step);
setScale(result);
};
const onZoomOut = () => {
}, 50);

const onZoomOut = throttle(() => {
const result = positiveSubtract(scale.value, step);
setScale(result);
};
}, 50);

const resetScale = () => {
scale.value = defaultScale ?? 1;
};
Expand Down
1 change: 0 additions & 1 deletion src/image-viewer/image-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ export default defineComponent({
const onWheel = (e: WheelEvent) => {
e.preventDefault();
const { deltaY } = e;

deltaY > 0 ? onZoomOut() : onZoomIn();
};

Expand Down
Loading