Instructions: Hover over an Image.
Konva Zoom Image on Hover Demoview raw<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/konva@4.0.18/konva.min.js"></script> <meta charset="utf-8" /> <title>Konva Zoom Image on Hover Demo</title> <style> body { margin: 0; padding: 0; overflow: hidden; background-color: #f0f0f0; } </style> </head> <body> <div id="container"></div> <script> var width = window.innerWidth; var height = window.innerHeight;
var stage = new Konva.Stage({ container: 'container', width: width, height: height });
var layer = new Konva.Layer();
stage.add(layer);
var imageObj = new Image(); imageObj.onload = function() { var backgroundImage = new Konva.Image({ x: 0, y: 0, width: width, height: height, image: imageObj }); layer.add(backgroundImage); layer.draw(); };
imageObj.src = '/assets/space.jpg';
var zoomLevel = 2; layer.on('mouseenter', function() { layer.scale({ x: zoomLevel, y: zoomLevel }); layer.draw(); });
layer.on('mousemove', function(e) { var pos = stage.getPointerPosition(); layer.x(-pos.x); layer.y(-pos.y); layer.draw(); });
layer.on('mouseleave', function() { layer.x(0); layer.y(0); layer.scale({ x: 1, y: 1 }); layer.draw(); }); </script> </body> </html>
|