Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG Filters in Firefox

For some reason I can't get my SVG filters to work in Firefox. They work fine in Opera, however. The element whose property I set to the filter on just disappears. It's very odd.

Here's my javascript code:

defsElement = SVGDoc.createElement("defs");
var filterElement = SVGDoc.createElement("filter");
filterElement.setAttribute( "id", "cm-mat");
filterElement.setAttribute( "filterUnits", "objectBoundingBox");

var fecolormatrixElement = SVGDoc.createElement("feColorMatrix");
fecolormatrixElement.setAttribute("type", "matrix");
fecolormatrixElement.setAttribute("in", "SourceGraphic");
fecolormatrixElement.setAttributeNS(null, "values", "1 1 1 1 1  2 2 2 2 1  1 1 1 1 1  1 1 1 1 1");
filterElement.appendChild(fecolormatrixElement);
defsElement.appendChild(filterElement);
SVGDoc.documentElement.insertBefore(defsElement, SVGDoc.documentElement.childNodes.item(1));

partRef = getElementFromID(SVGDoc.documentElement, part);
if(partRef != null)
{
    partRef.style.setProperty('filter', 'url(#cm-mat)', null);
}

Any Thoughts? Thanks

like image 736
Nick Avatar asked May 17 '10 19:05

Nick


People also ask

Can SVG have blur?

Filters are SVG's mechanism to create sophisticated effects. A basic example is to add a blur effect to SVG content. While basic blurs can be achieved with the help of gradients, the blur filter is needed to do anything beyond.

How do you blur SVG?

Code explanation:The blur effect is defined with the <feGaussianBlur> element. The in="SourceGraphic" part defines that the effect is created for the entire element. The stdDeviation attribute defines the amount of the blur. The filter attribute of the <rect> element links the element to the "f1" filter.

What is feColorMatrix?

feColorMatrix is an SVG filter primitive that allows the manipulation of color values across color channels. It provides more powerful color manipulation flexibility than CSS shorthand filters. It is always a child element of an SVG filter element.

What is SVG Filter in Illustrator?

Jul 13th, 2022 Illustrator. SVG or Scalable Vector Graphics have one serious advantage over the regular image formats: they are infinitely scalable, which means there is no degradation of quality no matter how big or small you make the image. However, SVG is not only used for images.


1 Answers

Paul Irish made a demo applying SVG Filters to HTML 5 video.

The source code for the live demo shows how to switch between filters. In that case, all the SVG pieces are written directly into the page as tags, not inserted dynamically via JavaScript.

It might help to try and get it working using straight up tags, then switch over to JavaScript once it's working. There may be some strange oddity of the implementation (bug) which only expresses itself when created dynamically (/speculation).

Also, it may depend no what version of Firefox you're using. I'm not sure which version started supporting SVG filters, but Paul's post seems to suggest it may require a nightly build.

Good luck!

like image 58
jimbo Avatar answered Sep 23 '22 02:09

jimbo