Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findAncestor (el, sel) {
- while ((el = el.parentElement) && !((el.matches || el.matchesSelector).call(el,sel)));
- return el;
- }
- function lazyloadHasChild() {
- document.querySelectorAll('.js-lazyload__has-child').forEach(function(el) {
- el.classList.add('js-lazyload__parent-placeholder');
- });
- document.querySelectorAll('.js-lazyload__has-child img').forEach(function(ch) {
- "load error".split(" ").forEach(function(ev) {
- ch.addEventListener(ev, function() {
- const ancestor = findAncestor(ch,'.js-lazyload__has-child');
- ancestor.classList.add('js-lazyload__has-child-loaded');
- ancestor.classList.remove('js-lazyload__parent-placeholder');
- });
- });
- });
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement