-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43569de
commit 30781c8
Showing
4 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,59 @@ | ||
export default function useTargetScale (realWidth, realHeight, realScale) {} | ||
import { reactive, computed, watch } from 'vue' | ||
import useDebounceCallback from './useDebounceCallback' | ||
|
||
/** | ||
* 目标缩放延迟处理 | ||
*/ | ||
export default function useTargetScale (state, speed) { | ||
const innerState = reactive({ | ||
lead: true, | ||
scale: state.scale | ||
}) | ||
|
||
const moveScale = useDebounceCallback( | ||
(current) => { | ||
state.pause = true | ||
Object.assign(innerState, { | ||
lead: false, | ||
scale: current | ||
}) | ||
}, | ||
{ wait: speed } | ||
) | ||
|
||
watch(() => state.scale, () => { | ||
state.pause = false | ||
innerState.lead = true | ||
moveScale(state.scale) | ||
}) | ||
|
||
const autoWidth = computed(() => { | ||
if (innerState.lead) { | ||
return state.width * innerState.scale | ||
} else { | ||
return state.width * state.scale | ||
} | ||
}) | ||
|
||
const autoHeight = computed(() => { | ||
if (innerState.lead) { | ||
return state.height * innerState.scale | ||
} else { | ||
return state.height * state.scale | ||
} | ||
}) | ||
|
||
const autoScale = computed(() => { | ||
if (innerState.lead) { | ||
return state.scale / innerState.scale | ||
} else { | ||
return 1 | ||
} | ||
}) | ||
|
||
return { | ||
autoWidth, | ||
autoHeight, | ||
autoScale | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters