Making an image scale mouse over on HTM5 <canvas>

JavascriptWeb DevelopmentFront End Scripts

To make an image scale on mouse over, use Vanilla JavaScript library.

On mouse move, set it like the following:

function move(e) {
   var pos = getMousePos(myCanvas, e);
   context.drawImage(img, -pos.x, -pos.y, img.width, img.height);
}

For canvas:

//add event listener we need
myCanvas.addEventListener('mouseout', display, false);
myCanvas.addEventListener('mousemove', move, false);


function display() {
   context.drawImage(img, 0, 0, img.width>>1, img.height>>1);
}
raja
Published on 11-Apr-2018 08:00:55
Advertisements