$(function () { // banner的调用方法 $('.storageBanner').each(function () { var $this = $(this) var win_W = $(window).width(); var w,h; var size,imgSrc; var $lazy = $this.find(".bannerImg .J-ebg-replace-img-lazyload") if(win_W<=768){ size = $this.data("wap-size"); if($lazy.length){ imgSrc = $lazy.data("original"); }else{ $lazy = $this.find(".bannerImg .replaceimg") imgSrc = $lazy.data("wapsrc"); } }else{ size = $this.data("pc-size"); if($lazy.length){ imgSrc = $lazy.data("original"); }else{ $lazy = $this.find(".bannerImg .replaceimg") imgSrc = $lazy.data("pcsrc"); } } if( size && size.indexOf("*")) { w = $.trim(size.split("*")[0]); h = $.trim(size.split("*")[1]); initAdaptiveRotation($this,w,h) }else if(imgSrc){ loagImg(imgSrc,function(width,height){ initAdaptiveRotation($this,width,height) }) } }) /** * load img get width and height */ function loagImg(src,callback){ if(src){ var img = new Image(); img.onload=function (ev) { if(typeof callback=="function"){ callback(img.width,img.height,img); } } img.src=src; } } /** * init adaptiveRotation */ function initAdaptiveRotation($this,w,h){ $this.adaptiveRotation({ autoRotation:!!$this.data("auto-rotation") || $this.data("auto-rotation") == null, time:$this.data("auto-time")*1||5000, 'proportion': w / h, 'proportionMobile':w / h, 'Resolution':992 }); } /*title为空的时候*/ var $title = $(".storageBanner").find(".banner-text .title") var $topTitle = $(".storageBanner").find(".banner-text .top-title") if($title.is(":hidden")){ $title.html($topTitle.html()).show(); $topTitle.hide(); } });