要在鼠标悬停时缩放图像,请使用Vanilla JavaScript库。
鼠标移动时,如下设置:
function move(e) { var pos = getMousePos(myCanvas, e); context.drawImage(img, -pos.x, -pos.y, img.width, img.height); }
对于画布:
//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); }