美文网首页
大屏小屏的替换图片

大屏小屏的替换图片

作者: leleo | 来源:发表于2019-08-21 23:30 被阅读0次
    window.Base = window.Base || function () {};
    
    // 大屏小屏的替换图片
    Base.prototype.ebgReplaceImgLazyLoad = function () {
      function init() {
        if ($('.J-ebg-replace-img-lazyload').length > 0) {
          var win_w = $(window).width();
          $('.J-ebg-replace-img-lazyload').each(function () {
            var $this = $(this);
            var src = $this.attr("src");
            var img1920 = $this.data("pc-l");
            var img1600 = $this.data("pc-s");
            var img1200 = $this.data("ipad-h");
            var img992 = $this.data("ipad-s");
            var img750 = $this.data("wap");
            if (win_w > 1600) {
              $this.attr('data-original', img1920 || img1600 || img1200 || img992 || img750 || src);
            } else if (win_w > 1200) {
              $this.attr('data-original', img1600 || img1920 || img1200 || img992 || img750 || src);
            } else if (win_w > 992) {
              $this.attr('data-original', img1200 || img1600 || img1920 || img992 || img750 || src);
            } else if (win_w > 750) {
              $this.attr('data-original', img992 || img1200 || img1600 || img1920 || img750 || src);
            } else {
              $this.attr('data-original', img750 || img992 || img1200 || img1600 || img1920 || src);
            }
          });
        };
      }
      //对外重新初始化
      $("body").on("ebgReplaceImgLazyLoad", function () {
        init();
      });
      init();
    }
    
    var baseLib = new Base();
    baseLib.ebgReplaceImgLazyLoad() ////5种尺寸图片的图片替换
    

    相关文章

      网友评论

          本文标题:大屏小屏的替换图片

          本文链接:https://www.haomeiwen.com/subject/mrcmsctx.html