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
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.
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.
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;
}
});
https://jsfiddle.net/r7hkmaeo/84/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With