無限スクロールローディング(一回目の要求が完了してから二回目の要求が送られます)
1966 ワード
var time1;
var srcollOld = 0,srcollNow = 0,scrollFun = false;
$(window).scroll(function () {
//$(window).scrollTop()
//$(window).height()
//$(document).height()
var bot = 50; //bot
if ((bot + $(window).scrollTop() ) >= ($(document).height() - $(window).height())) {
srcollNow = $(window).scrollTop();
if(srcollNow >= srcollOld){
if(!scrollFun){
//
scrollFun = true;
clearTimeout(time1);
time1=window.setTimeout(function(){
loadAjax()
},500);
}
}
srcollOld = srcollNow;
}
});
function loadAjax(){
$.ajax({
url: url,
type: type,
success:function (data) {
scrollFun = false;
if (data.success == true) {
}else{
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
scrollFun = false;
}
});
}
VUEが最後までスクロールしてデータをロードする
mounted(){
this.$refs.viewBox.addEventListener('scroll', this.loadingMore, false);
this.getActivtyList()
},
methods: {
getActivtyList(){
},
loadingMore(){
// scrollTop ,
var scrollTop = this.$refs.viewBox.scrollTop;
// windowHeight
var windowHeight = this.$refs.viewBox.clientHeight;
// scrollHeight
var scrollHeight = this.$refs.viewBox.scrollHeight;
//
if(scrollTop+windowHeight==scrollHeight){
//
console.log(" "+scrollTop+" "+windowHeight+" "+scrollHeight);
if(Math.ceil(this.total/this.pageSize) > this.pageNo){
this.pageNo += 1;
this.getActivtyList()
}
}
}
}