Skip to content

Commit 90d33b0

Browse files
committed
fix: slider position error when zoom is not 1 #227
1 parent 46b71b2 commit 90d33b0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

components/vc-slider/src/utils.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ export function getPrecision (step) {
3535
}
3636

3737
export function getMousePosition (vertical, e) {
38-
return vertical ? e.clientY : e.pageX
38+
let zoom = 1
39+
if (window.visualViewport) {
40+
zoom = +(window.visualViewport.width / document.body.getBoundingClientRect().width).toFixed(2)
41+
}
42+
return (vertical ? e.clientY : e.pageX) / zoom
3943
}
4044

4145
export function getTouchPosition (vertical, e) {
42-
return vertical ? e.touches[0].clientY : e.touches[0].pageX
46+
let zoom = 1
47+
if (window.visualViewport) {
48+
zoom = +(window.visualViewport.width / document.body.getBoundingClientRect().width).toFixed(2)
49+
}
50+
return (vertical ? e.touches[0].clientY : e.touches[0].pageX) / zoom
4351
}
4452

4553
export function getHandleCenterPosition (vertical, handle) {

0 commit comments

Comments
 (0)