大屏小屏的替换图片

2019-08-21  本文已影响0人  leleo
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种尺寸图片的图片替换
上一篇下一篇

猜你喜欢

热点阅读