Catching Mac trackpad zoom

后端 未结 5 546
感动是毒
感动是毒 2020-12-24 03:32

Currently in my application i am catching the mouse wheel events and perform zoom in or out on a Canvas element. If user uses Mac and tries to perform zoom with the trackpad

5条回答
  •  佛祖请我去吃肉
    2020-12-24 04:18

    Starting from Safari 9.1 you can catch zoom and rotation events from OSX devices. For more information read the GestureEvent Class Reference. Note that this only works in Safari but since your question was about "Mac trackpad zoom" I think this is what you are looking for.

    function zoom(e) {
      console.log(e.scale)
      e.preventDefault()
    }
    document.addEventListener('gesturestart', zoom)
    document.addEventListener('gesturechange', zoom)
    document.addEventListener('gestureend', zoom)


    Side note: these events are also supported in Safari on iOS.

提交回复
热议问题