问题
I have a lot of SVG images, with filter-animations defined inside of them. To describe the problem I made jsFiddle: http://jsfiddle.net/kinos/3vhtmsy5/47/ You can see there inline SVG, which is blinking with red alarm filter and fabric.js canvas with loaded SVG without blinking.
HTML (Inline SVG takes too much place to add it here):
<div id="svg"></div>
<canvas id="nativeCanvas"></canvas>
Javascript:
var canvas = new fabric.Canvas('nativeCanvas', {width: 1000, height: 600});
fabric.loadSVGFromString(document.getElementById('svg').innerHTML, function (objects, options) {
var obj = fabric.util.groupSVGElements(objects, options);
obj.set({left: 200, top: 250});
canvas.add(obj);
}, addSVGProperties);
function addSVGProperties(el, obj) {
obj.id = el.getAttribute('id');
}
I want to load predefined filters from SVG and manage them - apply/deapply to elements.
I made a small research, which described at google groups: https://groups.google.com/forum/#!topic/fabricjs/q1ASN-fsbpk
As a result I have found two problems:
- Fabric.js doesn't parse filters from SVG images
- Fabric.js have no option to apply it's own filters to loaded SVG(I'm not sure about this part).
And I see two options:
- Write lots of code to add filters parsing and applying.
- Find the way to use Fabric.js native filters.
Any ideas how to achive required behaviour without rewriting whole library? :)
来源:https://stackoverflow.com/questions/51819991/fabric-js-how-to-use-predefined-svg-filters