Skip to content

How to create filter that is only used on certain elements in the SVG? #63

@sqwarellc

Description

@sqwarellc

For my project, I am developing a control surface that is a window-filling SVG, with various graphical elements to comprise buttons, and I would like to use filters to indicate the button states as well as for simple decoration. In particular, feDropShadow will be used a lot, but not on the whole image.

I have followed the example on creating a reusable filter, such as:
var filter = new SVG.Filter();

However, when I attach this filter to my main image as well as an element, it affects the whole image...

myImage.filterWith(filter);
myParticularShape.filterWith(filter);

That seems to make sense. But if I only attach it to the elements that I want to affect, it doesn't work, because the filter information doesn't show up in the definitions section of the image. (The individual elements do include references to the filter, but there is no definition.)

Is there a way to define the filter in the SVG without using it except on particular elements?

(And to kill two birds with one stone, if your response includes an example of invoking feDropShadow on a cricle, while still preserving the appearance of the circle itself, that would really help me out.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions