/** * Created by Administrator on 2018/3/22 0022. */ var Template; var w = $(window).width(); $(window).resize(function () { w = $(window).width(); }); var swiper_html=[]; var swiper_container=[]; var swiper_slide=[]; var slide_a=[]; var slide_img=[]; { var imgLb = function (templateClassName, initialW, initialH, maxHeight, minHeight) { swiper_container=$('.'+ templateClassName).parent(".swiper-container1");//得到轮播图的容器,宽度已知 swiper_slide=$('.' + templateClassName + ' .swiper-slide'); //得到轮播图的滑块 slide_a=swiper_slide.find("a"); slide_a.css({"width":"100%","height":"100%"}); imgW(1); $(window).resize(function () { imgW(0); }); var mySwiper; function imgW(fn_param) { swiper_container.width("100%"); var swiper_container_w=swiper_container.width(); //得到轮播图容器的宽度 swiper_slide.css("width",swiper_container_w); //现设轮播图的滑块的宽和轮播图容器的高一样 var swiper_slide_w=swiper_slide.width(); var swiper_slide_sh=swiper_slide_w* initialH/initialW; //得到与图片比例一致的高 if(swiper_slide_sh > minHeight){ //如果得出的高比设置的最小高度要大 swiper_slide.css("height",swiper_slide_sh); swiper_container.css("height",swiper_slide_sh); ImgC_swiper(initialW,initialH); }else { //如果得出的高比设置的最小高度要小,滑块的高设为最小高度 swiper_slide.css("height",minHeight); swiper_container.css("height",minHeight); ImgC_swiper(initialW,initialH); } $('.swiper-container1 .swiper-slide').css('overflow','hidden'); $('.innerMain .innerBanner').height($('.swiper-container1').height()); if(fn_param==1){ $('.swiper-container1 .templateImg .swiper-slide').each(function () { swiper_html.push($(this).html()); }); } if (fn_param==0){ // $('.swiper-container1').html(swiper_html); mySwiper.removeAllSlides(); for (var i=0,j=swiper_html.length;i0){ //图片的宽大于容器的宽 img.css("width","auto"); img.css("height","100%"); var margin_w=0-(img.width()-contentw)/2; img.css("margin-left",margin_w+"px").css("margin-top","0px").css("margin-right",margin_w+"px").css("margin-bottom","0px"); }else if(difference==0){ img.css("width","100%"); img.css("height","100%"); img.css("margin-top","0px").css("margin-left","0px").css("margin-bottom","0px").css("margin-right","0px"); } }); }