html - Is it possible to distort SVG text dynamically? -
is possible distort svg text dynamically?
for example, apply filters shifting parameters based on temporal data?
thanks.
yes, it's possible:
let step = () => { let blur = document.queryselector('svg > #blur > fegaussianblur'); let value = parsefloat(blur.getattribute('stddeviation')); blur.setattribute('stddeviation', value * 1.05); requestanimationframe(step); }; requestanimationframe(step);
<svg width="250" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <filter id="blur"> <fegaussianblur in="sourcegraphic" stddeviation="1"/> </filter> <text x="15" y="50" font-size="35" filter="url(#blur)">hello world!</text> </svg>
probably better use css or smil animation though (smil snippet provided @kaiido):
<svg width="250" height="100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <filter id="blur"> <fegaussianblur in="sourcegraphic" stddeviation="0"> <animate attributetype="xml" attributename="stddeviation" from="0" to="5" dur="1s" begin="0s; backward.end + 1s" id="forward" /> <animate attributetype="xml" attributename="stddeviation" from="5" to="0" dur="1s" begin="forward.end" id="backward" /> </fegaussianblur> </filter> <text x="15" y="50" font-size="35" filter="url(#blur)">hello world!</text> </svg>
Comments
Post a Comment