<!DOCTYPE html> <html> <head> <script src="https://unpkg.com/[email protected]/konva.min.js"></script> <meta charset="utf-8" /> <title>Konva Image Border Highlighting 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 darthVaderImg = new Konva.Image({ x: 20, y: 20, width: 200, height: 137, stroke: 'red', strokeWidth: 10, draggable: true }); layer.add(darthVaderImg);
var yodaImg = new Konva.Image({ x: 240, y: 20, width: 93, height: 104, draggable: true, stroke: 'red', strokeWidth: 10 }); layer.add(yodaImg);
var imageObj1 = new Image(); imageObj1.onload = function() { darthVaderImg.image(imageObj1); layer.draw(); }; imageObj1.src = '/assets/darth-vader.jpg';
var imageObj2 = new Image(); imageObj2.onload = function() { yodaImg.image(imageObj2); layer.draw(); }; imageObj2.src = '/assets/yoda.jpg';
layer.on('mouseover', function(evt) { var shape = evt.target; document.body.style.cursor = 'pointer'; shape.strokeEnabled(false); layer.draw(); }); layer.on('mouseout', function(evt) { var shape = evt.target; document.body.style.cursor = 'default'; shape.strokeEnabled(true); layer.draw(); }); </script> </body> </html>
|