Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll vertically with two fingers

I'm working on a sketch web application (using angular) and, as the one finger gesture is used to draw, I would like to be able to scroll vertically in the sketch content using two fingers.

When a try to scroll with two fingers, safari exits the current tab and show the list of opened tabs. I can cancel this behaviour by calling preventDefault() on the TouchEvent if e.touches.length > 1 but (obviously) that doesn't scroll the content. I could, of course, implement a solution that would dynamically scroll after calling e.preventDefault(), but that's a bit tricky.

I would like to know if someone knows an easier/better solution?

Thanks

like image 527
user108828 Avatar asked Jul 07 '20 13:07

user108828


People also ask

How do I use two-finger scrolling in Windows 10?

To find the touchpad's options to activate the two-finger scrolling open Settings > Devices > "Mouse" in the left menu > "Additional mouse options" on the right side > You should see a tab of the touchpad manufacturer, open it and click "Settings" or "Options" there you can change some touchpad options.

Why can't I scroll with two fingers anymore Windows 11?

Click on Touchpad. After that, click on Scroll & zoom to open the menu. Here, make sure to check the box next to Drag two fingers to scroll. That is it for the first method.


1 Answers

Finally, I implement a basic solution based on the touchmove and touchstart events.

let lastTouchY;

element.addEventListener('touchstart', (event) =>
{
  if (event.touches.length === 2)
  {
    event.preventDefault();

    lastTouchY = event.touches[0].clientY;
  }
});

element.addEventListener('touchmove', (event) =>
{
  if (event.touches.length === 2)
  {
    event.preventDefault();

    const delta = lastTouchY - event.touches[0].clientY;
    lastTouchY = event.touches[0].clientY;

    element.scrollTop += delta;
  }
});

JSFiddle

https://jsfiddle.net/r7hkmaeo/84/

like image 155
user108828 Avatar answered Sep 25 '22 23:09

user108828