set MOVE_EDGE to 25% of either dimension

This commit is contained in:
Tomáš Mládek 2021-01-11 22:37:20 +01:00
parent f3eb39e034
commit bb085c174e

View file

@ -189,7 +189,8 @@ export default defineComponent({
} }
// Edge scrolling // Edge scrolling
const MOVE_EDGE = 75; const MOVE_EDGE_X = window.innerWidth * .25;
const MOVE_EDGE_Y = window.innerHeight * .25;
const MAX_SPEED = 20; const MAX_SPEED = 20;
if (document.fullscreenElement && mouse) { if (document.fullscreenElement && mouse) {
@ -197,21 +198,21 @@ export default defineComponent({
let verticalShift: number; let verticalShift: number;
const transform = pz.getTransform(); const transform = pz.getTransform();
if (mouse.clientX < MOVE_EDGE || mouse.clientX > window.innerWidth - MOVE_EDGE) { if (mouse.clientX < MOVE_EDGE_X || mouse.clientX > window.innerWidth - MOVE_EDGE_X) {
const horizontalEdgeDistance = const horizontalEdgeDistance =
(mouse.clientX < window.innerWidth / 2) ? mouse.clientX : (mouse.clientX - window.innerWidth); (mouse.clientX < window.innerWidth / 2) ? mouse.clientX : (mouse.clientX - window.innerWidth);
const horizontalRatio = (MOVE_EDGE - Math.abs(horizontalEdgeDistance)) / MOVE_EDGE; const horizontalRatio = (MOVE_EDGE_X - Math.abs(horizontalEdgeDistance)) / MOVE_EDGE_X;
const direction = mouse.clientX < MOVE_EDGE ? 1 : -1; const direction = mouse.clientX < MOVE_EDGE_X ? 1 : -1;
horizontalShift = horizontalRatio * direction * MAX_SPEED; horizontalShift = horizontalRatio * direction * MAX_SPEED;
} else { } else {
horizontalShift = 0; horizontalShift = 0;
} }
if (mouse.clientY < MOVE_EDGE || mouse.clientY > window.innerHeight - MOVE_EDGE) { if (mouse.clientY < MOVE_EDGE_Y || mouse.clientY > window.innerHeight - MOVE_EDGE_Y) {
const verticalEdgeDistance = const verticalEdgeDistance =
(mouse.clientY < window.innerHeight / 2) ? mouse.clientY : (mouse.clientY - window.innerHeight); (mouse.clientY < window.innerHeight / 2) ? mouse.clientY : (mouse.clientY - window.innerHeight);
const verticalRatio = (MOVE_EDGE - Math.abs(verticalEdgeDistance)) / MOVE_EDGE; const verticalRatio = (MOVE_EDGE_Y - Math.abs(verticalEdgeDistance)) / MOVE_EDGE_Y;
const direction = mouse.clientY < MOVE_EDGE ? 1 : -1; const direction = mouse.clientY < MOVE_EDGE_Y ? 1 : -1;
verticalShift = verticalRatio * direction * MAX_SPEED; verticalShift = verticalRatio * direction * MAX_SPEED;
} else { } else {
verticalShift = 0; verticalShift = 0;