How to trigger MacBook trackpad haptic feedback on a website?

Viewed 698

I'm writing a web application with a lot of drag and drop functionality and I want to enable haptic feedback (when possible, using macOS 10.11+ with a Force Touch trackpad) for actions like "snapping in" while dragging items.

Is this possible (I know it's impossible to support every platform, but at least when hardware supports it)? I've tried navigator.vibrate with different time values/patterns but it doesn't seem to do anything even if it returns true.

1 Answers

Should work with the Force Touch events, one of which is webkitmouseforcedown

someElement.addEventListener("webkitmouseforcedown", myFunction, false);

You can read more about this and the other events here

Please note that this will work only on Safari unfortunately

Related