Skip to content

Instantly share code, notes, and snippets.

View H4ad's full-sized avatar

Vinicius Lourenço H4ad

View GitHub Profile
@H4ad
H4ad / README.md
Last active August 5, 2020 19:05 — forked from ValentinFunk/README.md
Fixes SVG Gradients for Safari by changing fill URLs to the current pathname. Also fixes xlink:href URLs.

Snippet to fix SVG issues in Angular (2+) with Safari, Firefox and Chrome

This listens to Angular route changes and on route change does the following:

  1. Replaces the link in <use xlink:href="#some-id"></use> by a path prefixed version
  2. Replaces the fill property in referenced SVGs by a path prefixed version
  3. Replaces the style in <svg style="fill: url(#gradient)"> with a prefixed version

Adapted from Gist by Leon Derijke