Skip to main content
charlesn79540358
Inspiring
November 2, 2017
Answered

Zoom in and out feature

  • November 2, 2017
  • 2 replies
  • 681 views

Hello,

Is there a  way to create a zoom in and out feature with using mouse scrolling?

Thanks

    This topic has been closed for replies.
    Correct answer Colin Holgate

    For ActionScript you could read articles like this one:

    Flash Mouse Wheel Support | Hook - Labs

    For HTML5 Canvas, here's what @klad suggested in another post:

    document.getElementById('canvas').addEventListener('mousewheel',f.bind(this));

    document.getElementById('canvas').addEventListener('DOMMouseScroll',f.bind(this));

    function f(e){

    //e.detail

    }

    Exactly like that it's not the whole answer, there is wheelDeltaY, so this will give you a useful number about how quickly the user was wheeling:

    document.getElementById('canvas').addEventListener('mousewheel',f.bind(this));

    document.getElementById('canvas').addEventListener('DOMMouseScroll',f.bind(this));

    function f(e){

       alert(e.wheelDeltaY);

    }

    But, read articles like this about how that only works in some browsers, and for other approaches:

    mousewheel - Event reference | MDN

    Once you have a usable value you would then need more code to sensibly scale the image.

    2 replies

    Preran
    Legend
    November 3, 2017

    Please place a feature request with the team using this link Feature Request/Bug Report Form

    Colin Holgate
    Inspiring
    November 3, 2017

    Yes, hold down the Command key (Ctrl on Windows I would think), and mouse wheel. It's a shame they didn't use the alt/option key to make it the same as Photoshop and Illustrator.

    charlesn79540358
    Inspiring
    November 3, 2017

    Hello,

    That is not what I meant. Can we create a zooming feature on our project. Like build one on our image so when a user runs the website they are able to zoom in and out on the image.

    Thank you

    Colin Holgate
    Colin HolgateCorrect answer
    Inspiring
    November 3, 2017

    For ActionScript you could read articles like this one:

    Flash Mouse Wheel Support | Hook - Labs

    For HTML5 Canvas, here's what @klad suggested in another post:

    document.getElementById('canvas').addEventListener('mousewheel',f.bind(this));

    document.getElementById('canvas').addEventListener('DOMMouseScroll',f.bind(this));

    function f(e){

    //e.detail

    }

    Exactly like that it's not the whole answer, there is wheelDeltaY, so this will give you a useful number about how quickly the user was wheeling:

    document.getElementById('canvas').addEventListener('mousewheel',f.bind(this));

    document.getElementById('canvas').addEventListener('DOMMouseScroll',f.bind(this));

    function f(e){

       alert(e.wheelDeltaY);

    }

    But, read articles like this about how that only works in some browsers, and for other approaches:

    mousewheel - Event reference | MDN

    Once you have a usable value you would then need more code to sensibly scale the image.