Update HTML5 canvas rectangle on hover


To update HTML5 canvas rectangle on hover, try to run the following code:

var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.rect(20,20,150,100);
context.stroke();

$(canvas).hover(function(e){
   context.fillStyle = blue;
   context.fill();
});

Updated on: 29-Jan-2020

394 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements