Advertisement
SpykeRel04D

Untitled

Nov 10th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. function findAncestor (el, sel) {
  2. while ((el = el.parentElement) && !((el.matches || el.matchesSelector).call(el,sel)));
  3. return el;
  4. }
  5.  
  6. function lazyloadHasChild() {
  7. document.querySelectorAll('.js-lazyload__has-child').forEach(function(el) {
  8. el.classList.add('js-lazyload__parent-placeholder');
  9. });
  10.  
  11. document.querySelectorAll('.js-lazyload__has-child img').forEach(function(ch) {
  12. "load error".split(" ").forEach(function(ev) {
  13. ch.addEventListener(ev, function() {
  14. const ancestor = findAncestor(ch,'.js-lazyload__has-child');
  15. ancestor.classList.add('js-lazyload__has-child-loaded');
  16. ancestor.classList.remove('js-lazyload__parent-placeholder');
  17. });
  18. });
  19.  
  20. });
  21. };
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement