const stage = new Konva.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight
});
const layer = new Konva.Layer();
stage.add(layer);
const rect1 = new Konva.Rect({
x: 50,
y: 50,
width: 100,
height: 100,
fill: 'green'
});
layer.add(rect1);
const group = new Konva.Group({
x: 100,
y: 100,
draggable: true,
})
layer.add(group);
const rect2 = new Konva.Rect({
width: 50,
height: 50,
fill: 'green',
filters: [Konva.Filters.Blur],
blurRadius: 20,
});
group.add(rect2);
rect2.cache({ width: 70, height: 70 });
const rect3 = new Konva.Rect({
width: 100,
height: 100,
fill: 'red',
opacity: 0.4
});
group.add(rect3);
const rect4 = new Konva.Rect({
y: 100,
fill: 'blue',
width: 100,
height: 100,
opacity: 0.5,
draggable: true
});
layer.add(rect4);
const blurEl = document.createElement('div');
stage.content.appendChild(blurEl);
Object.assign(blurEl.style, {
position: 'absolute',
width: rect4.width()+ 'px',
height: rect4.height()+ 'px',
backdropFilter: 'blur(2px)',
pointerEvents: 'none'
});
function updateBlur() {
Object.assign(blurEl.style, {
top: rect4.y() + 'px',
left: rect4.x() + 'px'
});
}
updateBlur();
rect4.on('dragmove', () => {
updateBlur();
})
<script src="https://unpkg.com/konva@^8/konva.min.js"></script>
<div id="container"></div>