鴻蒙傳說(shuō)
2018-12-28 23:14:53
$(document).scroll(function (){ var scrollTop = $(this).scrollTop(); var scrollHeight = $(document).height(); var windowHeight = $(window).height(); if(scrollTop + windowHeight >= scrollHeight){ //這里是加載圖片ajax } });這是部分代碼,邏輯就是滑動(dòng)到底部的時(shí)候請(qǐng)求ajax,在安卓上可以一頁(yè)一頁(yè)正常加載,ios上則滑動(dòng)到底部一下加載好幾頁(yè),求教
1 回答

絕地?zé)o雙
TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊
加載好幾頁(yè)是因?yàn)閟croll事件被多次觸發(fā),可以用節(jié)流函數(shù)來(lái)控制觸發(fā)的時(shí)間間隔,比如underscore的throttle函數(shù):
var throttled = _.throttle(updatePosition, 100);
$(window).scroll(throttled);
function updatePosition(){
var scrollTop = $(this).scrollTop();
var scrollHeight = $(document).height();
var windowHeight = $(window).height();
if(scrollTop + windowHeight >= scrollHeight){
//這里是加載圖片ajax
}
}
添加回答
舉報(bào)
0/150
提交
取消