在 HTM5 上制作鼠标移过的图象缩放


要使图片在鼠标悬停时缩放,请使用原生 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);
}

更新于:29-Jan-2020

292 次浏览

开启您的 职业生涯

通过完成课程获得认证

立即开始
广告
© . All rights reserved.