Deferred insertion media
Getting Started
Source code on GitHub
Install:
<script src="../src/insertmedia.js"></script>
Usage:
document.addEventListener("DOMContentLoaded", function () {
insertmedia();
});
Use with options:
document.addEventListener("DOMContentLoaded", function () { insertmedia({
delay: 300, // delay. default: 300ms
immediately: true, // performing a delay true/false. Immediately or one at a time every "delay" ms. default: true
attr: 'data-insertmedia', // Processed attribute. default: data-insertmedia
});
});
Add an attribute to the block where we insert the media:
data-insertmedia='{"type" : "youtube", "src" : "https://www.youtube.com/embed/6Q6cCuSvFpI", "setting" : "autoplay=1&mute=1" }'
Options:
type*: youtube , twitch , html5 , img
src*: resource url https://example.com/img.jpg
width: Width available for this type of media
height: Height available for this type of media
setting: Settings available for this type of media
(*) - required