Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. function isOnScreen(a) {
  2. if (0 != a.length) {
  3. var t = jQuery(window),
  4. s = t.scrollTop(),
  5. l = t.height(),
  6. e = s + l,
  7. d = jQuery(a),
  8. i = d.offset().top,
  9. r = d.height(),
  10. h = i + r;
  11. return s <= i && i < e || s < h && h <= e || l < r && i <= s && e <= h
  12. }
  13. }
  14.  
  15. function lazyloadImages() {
  16. var a = $(".js-lazyload");
  17. 0 < a.length && a.each(function() {
  18. var a = $(this).attr("data-src"),
  19. t = $(this).attr("data-mob-src"),
  20. s = $(this).attr("data-mob-media-query"),
  21. l = "scroll" == $(this).attr("data-load");
  22. $(this).is("div") && 0 < a.length && (0 < !t.length && 0 < !s.length || 0 < t.length && 0 < !s.length || 0 < !t.length && 0 < s.length ? l ? isOnScreen($(this)) && ($(this).attr("style", "background-image:url(" + a + ")"), $(this).addClass("lazyloaded")) : ($(this).attr("style", "background-image:url(" + a + ")"), $(this).addClass("lazyloaded")) : window.matchMedia(s).matches ? l ? isOnScreen($(this)) && ($(this).attr("style", "background-image:url(" + a + ")"), $(this).addClass("lazyloaded")) : ($(this).attr("style", "background-image:url(" + a + ")"), $(this).addClass("lazyloaded")) : l ? isOnScreen($(this)) && ($(this).attr("style", "background-image:url(" + t + ")"), $(this).addClass("lazyloaded")) : ($(this).attr("style", "background-image:url(" + t + ")"), $(this).addClass("lazyloaded")))
  23. })
  24. }
  25. lazyloadImages(), $(window).on("resize scroll", function() {
  26. lazyloadImages()
  27. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement