下面小编就为大家分享一篇swiper 解决动态加载数据滑动失效的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
两种解决方法
1、数据加载后进行swiper初始化
success:function(result){ var resultdata =eval("("+result+")"); if(resultdata.status == 1){ var dataList = resultdata.data; currentPage = resultdata.currentPage; pageCount = resultdata.pageCount; var html = ""; if(pageCount == 0){ html ='<div>' + resultdata.msg + '</div>'; }else{ for(var i in dataList){ var data = dataList[i]; html += '<div>' + '<div>' + '<div>' + '<div>' + '<img src="'+ data.artistAvatar +'" />' + '</div>'https://www.jb51.net/article/+'<div>' + '<div>' + data.artistName + '</div>' + '<div>' + data.artworkName + '</div>' + '<div>'+ data.typeName +'https://www.jb51.net/'+ data.width + '*' + data.height +'https://www.jb51.net/' +data.createYear + '</div>' + '</div><div>' + '<div>¥'+ data.marketPrice +'</div></div></div>' + '<div>删除</div></div></div>'; } } $("#list").append(html); //swiper初始化 var swiper = new Swiper('.swiper-container', { pagination: '.swiper-pagination', slidesPerView: 'auto', paginationClickable: true, spaceBetween: 0 }); }
2、swiper初始化加两行代码
swiper1 = new Swiper('.swiper-container', { initialSlide :0, observer:true,//修改swiper自己或子元素时,自动初始化swiper observeParents:true//修改swiper的父元素时,自动初始化swiper });
以上这篇swiper 解决动态加载数据滑动失效的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章: