2.2.0 • Published 5 years ago

@firstandthird/svg-injector v2.2.0

Weekly downloads
44
License
MIT
Repository
github
Last release
5 years ago

SVG Injector npm Build Status

Loads and caches an SVG file and injects it into the DOM.

Installation

npm install @firstandthird/svg-injector

Usage

In your project import the library:

import { loadSVG, injectSVG } from '@firstandthird/svg-injector'

The injectSVG method will be automatically called once the DOMContentLoaded event is fired using window.svgLocation as parameter.

Events

Custom events are fired on injection.

EventWhereWhen
svgicons:loadedbodySVG is injected into the DOM

API

loadSVG(url, callback)

Loads an SVG file.

Parameters

url - {string} - A valid URL to the SVG file.

[callback] {function} - Callback function called once the SVG is loaded.

Example

loadSVG('image.svg', (svg) => {
  console.log(svg); // prints the SVG content
});

injectSVG(url)

Injects an SVG into the DOM. Calls loadSVG.

Parameters

url - {string} - A valid URL to the SVG file. Fires a svgicons:loaded event when completed.

Example

injectSVG('image.svg');
2.2.0

5 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.1

6 years ago

1.0.0

7 years ago