Zoom Canvas to Mouse Cursor

后端 未结 4 1921
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 15:03

I\'m programming a HTML5 < canvas > project that involves zooming in and out of images using the scroll wheel. I want to zoom towards the cursor like google maps does but

4条回答
  •  独厮守ぢ
    2020-11-22 15:53

    I took @Phrogz's answer as a basis and made a small library that enables canvas with dragging, zooming and rotating. Here is the example.

    var canvas = document.getElementById('canvas')
    //assuming that @param draw is a function where you do your main drawing.
    var control = new CanvasManipulation(canvas, draw)
    control.init()
    control.layout()
    //now you can drag, zoom and rotate in canvas
    

    You can find more detailed examples and documentation on the project's page

提交回复
热议问题