$(function(){ /*图片位置计算*/ var imgcount = function () { $('.img-count').each(function (index, element) { var imgh = $(this).height(); var imgw = $(this).width(); var $thisimg = $(this).find('img'); var img = new image(); img.onload = function () { if ($thisimg.data("img") === false) { return ''; } var imgwidth = img.width; var imgheight = img.height; if ((imgwidth / imgheight) < (imgw / imgh)) { $thisimg.css({'height': (imgw / imgh) * ((imgheight * 1.00) / imgwidth) * imgh, 'max-height': (imgw / imgh) * ((imgheight * 1.00) / imgwidth) * imgh, 'top': -((imgw / imgh) * ((imgheight * 1.00) / imgwidth) - 1) / 2 * imgh}) } else { $thisimg.css({'width': (imgh / imgw) * ((imgwidth * 1.00) / imgheight) * imgw, 'max-width': (imgh / imgw) * ((imgwidth * 1.00) / imgheight) * imgw, 'left': -((imgh / imgw) * ((imgwidth * 1.00) / imgheight) - 1) / 2 * imgw}) } } img.src = $thisimg.attr("src"); }); } //滚动设置 var swiper = new swiper('#newslist1', { effect : 'fade', fadeeffect: { crossfade: true, }, direction : 'horizontal', loop: true, autoplay : { delay:5000,//滚动速度 disableoninteraction: false, }, pagination: { el: '.adsn_page', clickable :true, }, on:{ init:function(){ var total=this.slides.length-2; $('.swiper-num .total').text('0'+total); this.emit('transitionend'); }, transitionend:function(){ var index=this.realindex+1; $(".swiper-num .active").text("0"+index); } } }); imgcount(); $(window).resize(function () { imgcount(); }); });