   

    var loadImages;

    $(document).ready(function(){
        loadImages();
    });

    $(document).on("scroll",function(){
        loadImages();
    });

    (loadImages = function(){
        $.each($(".lazy-img"), function(){
            var image = $(this);

            if(isOnScreen(image)){
                var url = image.data("url");
                if(image.attr("src") != url){
                    image.attr("src", url);
                }
            }
        })
    })();

    function isOnScreen(element){
        var win = $(window);
        var screenTop = win.scrollTop();
        var screenBottom = screenTop + win.height();
 
        var elementTop = element.offset().top;
        var elementBottom = elementTop + element.height();
 
        return elementBottom > screenTop && elementTop < screenBottom;        
}