$.ajax({ type : "get",url : "data.PHP",data : {type:1 },dataType:"json",beforeSend: function(){ $('.swiper-wrapper').html(''); },error:function(){ //alert("操作出错"); },success:function(res){ var html = ""; $.each(res['result'],function(i,item) { html += '<div class="swiper-slide"><a href="####"><img src="'+item.pic+'"></a></div>'; }); $('.swiper-wrapper').html(html); var swiper = new Swiper('.swiper-container',{ pagination: '.swiper-pagination',paginationClickable: true,observer: true,//修改swiper自己或子元素时,自动初始化swiper observeParents: true,//修改swiper的父元素时,自动初始化swiper onSlideChangeStart:function(sw){ var num = parseInt(sw.activeIndex); console.log('---'+ num); } }); } });
新增两句:
observer: true,//修改swiper自己或子元素时,自动初始化swiper observeParents: true,//修改swiper的父元素时,自动初始化swiper原文链接:https://www.f2er.com/ajax/160513.html