Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isOnScreen(a) {
- if (0 != a.length) {
- var t = jQuery(window),
- s = t.scrollTop(),
- l = t.height(),
- e = s + l,
- d = jQuery(a),
- i = d.offset().top,
- r = d.height(),
- h = i + r;
- return s <= i && i < e || s < h && h <= e || l < r && i <= s && e <= h
- }
- }
- function lazyloadImages() {
- var a = $(".js-lazyload");
- 0 < a.length && a.each(function() {
- var a = $(this).attr("data-src"),
- t = $(this).attr("data-mob-src"),
- s = $(this).attr("data-mob-media-query"),
- l = "scroll" == $(this).attr("data-load");
- $(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")))
- })
- }
- lazyloadImages(), $(window).on("resize scroll", function() {
- lazyloadImages()
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement