@fngr/loady
v0.1.7
Published
Load scripts after an event like a click on a button
Maintainers
Readme
loady
loady is a tiny and lightweight (1.4kb gzipped) library that loads scripts after a selected event was triggered – for example a click on a button. If the consent is already given, the script will be loaded immediately.
Installation
Install via npm
$ npm i @fngr/loadyUsage
import loady from '@fngr/loady'
loady({
triggerElement: document.getElementById('myButton'),
event: 'click',
storageItem: 'load-chartjs-consent',
script: 'https://cdn.jsdelivr.net/npm/[email protected]',
attributes: {
defer: true,
},
})Options
triggerElement: DOM Element, required
The DOM Element where the event listener will be added to.
event: String, required, default: 'click'
String of event type that triggers event listener on triggerElement
storageItem: String, required
Key of the item that will be placed in localStorage to determine consent
script: String, required
The URL of the script to be loaded after consent
attributes: Object, optional
Object of attributes that should be added to script tag. Something like { 'defer': true }
License
MIT
