set MOVE_EDGE to 25% of either dimension

master
Tomáš Mládek 2021-01-11 22:37:20 +01:00
parent f3eb39e034
commit bb085c174e
1 changed files with 8 additions and 7 deletions

View File

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