Skip to content

Commit

Permalink
Merge branch 'release/10.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
verlok committed Apr 27, 2018
2 parents 5640734 + 8d56fdf commit 4c85747
Showing 1 changed file with 37 additions and 3 deletions.
40 changes: 37 additions & 3 deletions demos/background_images.html
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,43 @@
</div>
<script src="../dist/lazyload.min.js"></script>
<script>
new LazyLoad({
elements_selector: "a"
});
(function () {
function logElementEvent(eventName, element) {
console.log(new Date().getTime(), eventName, element.getAttribute('data-src'));
}

function logEvent(eventName, elementsLeft) {
console.log(new Date().getTime(), eventName, elementsLeft + " images left");
}

function createImageFragment(srcUrl) {
var imageFragment = document.createElement('img');
imageFragment.setAttribute('src', srcUrl);
return imageFragment;
}

ll = new LazyLoad({
elements_selector: "a",
callback_enter: function (element) {
function callback_load(event) {
element.classList.remove('loading');
logElementEvent("LOADED", element);
imageFragment.removeEventListener('load', callback_load);
}
var imageFragment = createImageFragment(element.getAttribute('data-src'));
imageFragment.addEventListener('load', callback_load);
element.classList.add('loading');
logElementEvent("ENTERED", element);
},
callback_set: function (element) {
logElementEvent("SET", element);
},
callback_error: function(element) {
logElementEvent("ERROR", element);
element.src = "https://placeholdit.imgix.net/~text?txtsize=21&txt=Fallback%20image&w=220&h=280";
}
});
}());
</script>
</body>
</html>

0 comments on commit 4c85747

Please sign in to comment.