Why Lazy load doesn’t Perfectly?

Hello there I working on lazy load images and it works perfectly, but I face a problem when I have to add, different attributes in images extension to enhance the quality.

when I scroll down to the bottom at class has been added lazy-img, src attribute src has been implemented into the image tag and lazy load works perfectly.

where is my code which will only at the class lazy-img

this is the older jsFiddle not working
Older jsFiddle code

$(function($) {
  /**
   * @return {?}
   */
  $.fn.lazyimg = function() {
    return this.each(function() {
      /**
       * @return {undefined}
       */
      function o() {
        var threshold = $(window).height();
        if ($(window).scrollTop() + threshold > t.offset().top) {
          /** @type {!Image} */
          var a = new Image;
          /**
           * @return {undefined}
           */
          a.onload = function() {
            t.addClass("lazy-img");
          };
          a.src = s;
        }
      }
      var t = $(this);
      var a = t.attr("src");
      /** @type {number} */
      var i = Math.round(t.height());
      /** @type {string} */
      var s = "";
      s = a.match("s72-c") ? a.replace("/s72-c", i) : a;
      $(window).on("load scroll", o);
      o();
    });
  };
});

on other hand, in same condition my friend also used is jQuery code, which works perfectly without any problem.
he told me just rewrite the code reshuffle and use it for your project, but due to insufficient knowledge about jQuery I am not able to do this anyone can help me to rewrite this code again.

New jsFiddle working file
jsFiddle New

Please check this jsFiddle file it’s perfectly working for lazy load I want to arrange this code and so that I can use in my project.

I know it’s doesn’t sound good but I have to do nothing more good options available to use lazy load.
The permission has been taken from my friend that I can use this code for my project

Any kind of help or advice is highly appreciated