Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
<!DOCTYPE html>
<html>
<body>
<script>
svg.setAttribute('style', 'display: block; width: 0; height: 0');
dropShadowFilter.setAttribute('id', 'drop-shadow');
gaussianFilter.setAttribute('in', 'SourceAlpha');
gaussianFilter.setAttribute('stdDeviation', '0');
dropShadowFilter.appendChild(gaussianFilter);
offset.setAttribute('dx', '0');
offset.setAttribute('dy', '0');
offset.setAttribute('result', 'offsetblur');
dropShadowFilter.appendChild(offset);
flood.setAttribute('flood-color', 'rgba(0,0,0,1)');
dropShadowFilter.appendChild(flood);
composite.setAttribute('in2', 'offsetblur');
composite.setAttribute('operator', 'in');
dropShadowFilter.appendChild(composite);
merge.appendChild(mergeNode);
mergeNode.setAttribute('in', 'SourceGraphic');
merge.appendChild(mergeNode);
dropShadowFilter.appendChild(merge);
defs.appendChild(dropShadowFilter);
svg.appendChild(defs);
document.body.appendChild(svg);
</script>
<canvas id="canvas" width="100" height="100"></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.filter = 'url(#drop-shadow)';
offset.setAttribute('dy', '10');
ctx.fillStyle = '#0f0';
ctx.fillRect(25, 25, 50, 40);
</script>
</body>
</html>