我把來龍去脈說一遍,開始靜態(tài)swiper滾動正常,ajax加載也正常,兩個(gè)一組和發(fā)生第一個(gè)問題,那就是swiper無法滾動動態(tài)數(shù)據(jù)。我改為ajax加載之后馬上初始化swiper,ok,滾動問題解決了,那么就出現(xiàn)了第二個(gè)問題,點(diǎn)擊加載更多后局部刷新的時(shí)候會彈回頁面頂部,?$("").append();輸出方法無毛病,折騰兩天不知道問題出在哪?下面是代碼:html
????????<div?class="swiper-wrapper">
??????????<div?class="swiper-slide?slidescroll">????
????
???????<ul?class="img"?id="uiList">?
????</ul>
????
<botton?id="pull-up-label"style="">加載更多?</botton>
<botton?id="loading_icon"?style="display:?none;"?>加載中</botton>
</div>
?????</div>js代碼
$(document).ready(function()?{
var?Class="0";//當(dāng)前劇情????????
var?Type=1;//當(dāng)前分類id????????
var;//當(dāng)前語言????????
var?Letter="0";//當(dāng)前頭字母?a?b?c?d?
var?year="0";//當(dāng)前年代
var?page=1;//當(dāng)前分頁
var?refresh_open?=?true;
//首頁數(shù)據(jù)
$("#pull-up-label").click(function(){
?????if(refresh_open){
????????refresh_open?=?false;
????????$("botton[id='loading_icon']").css("display","");
????????$("#pull-up-label").css("display","none");
?????????$.ajax({
?????url:"index.php/label/json/page/"+page+"/class/"+Class+"/id/"+Type+"/lang/"+Lang+"/letter/"+Letter+"/year/"+year+".html",
????????success:function(result){
???????????????????$("botton[id='loading_icon']").css("display","none");
???????????????????$("#pull-up-label").css("display","");??????????
????????????????????if(result?!=?""){
???????????????????????$("#uiList").append(result);
?????????????????????page?+=1;
????????????????//內(nèi)容滾動初始化
??????????????var?swiper?=?new?Swiper('.scroll',?{??
?????????????????
???????????????slidesOffsetBefore:?72,
????????????????direction:?'vertical',
????????????????freeMode:?true,
????????????????slidesPerView:?'auto',
????????????????observer:?true,//修改swiper自己或子元素時(shí),自動初始化swiper??
????????????????observeParents:?true,//修改swiper的父元素時(shí),自動初始化swiper??
?
????????????});?
???????????????????setTimeout(function(){
???????????????????????refresh_open?=?true;
??
???????????????????},2000);
????????????????}else{
????????????????????$("#pull-up-label").html("無更多內(nèi)容!");
????????????????????$("#pull-up-label").attr("disabled","");
????????????????};
????
???????????}});
?????????}
});
$("#pull-up-label").trigger("click");
});
關(guān)于swiper和Ajax滾動的詭異問題?
憤怒de小菜鳥
2018-04-17 23:35:44