Để tạo tỷ lệ hình ảnh khi di chuột qua, hãy sử dụng thư viện Vanilla JavaScript.
Khi di chuyển chuột, hãy đặt nó như sau:
function move(e) {
var pos = getMousePos(myCanvas, e);
context.drawImage(img, -pos.x, -pos.y, img.width, img.height);
} Đối với 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);
}