이 스크롤더블 요청
$(document).ready(function(){
var tempScrollTop, currentScrollTop = 0;
$(document).scroll(function(){
currentScrollTop = $(document).scrollTop();
var ids = new Array();
if (tempScrollTop < currentScrollTop)
{
var result = currentScrollTop % 100;
if(result == 0)
{
//console.log('scroll happened');
var items = $(".item");
var items_l = items.length;
for(var i = 0; i < items_l; i++)
{
ids[i] = parseInt(items[i].id.replace(/\D+/g,""));
}
ids = ids.sort();
var last_id = ids[0];
$.ajax({
url: "ajax/load",
type: "POST",
data: {last_id : last_id},
success: function(res){
$("#content").append(res);
}
});
}
}
/*else if (tempScrollTop > currentScrollTop)
{
var result = currentScrollTop % 100;
if(result == 0)
{
$("#content").text("Вверх запрос " + result);
}
}*/
tempScrollTop = currentScrollTop;
})
});
을 스크롤 할 때 요청을 호출하는 자바 스크립트이며,이 컨트롤러의 방법입니다 1) 때로는 2 개의 동일한 레코드를 출력하는 이중 요청을 방지 할 수 있습니까? 내가 아래로 스크롤했을 때
2) 레코드를 스크롤 할 때마다 100 픽셀이 추가되지만, 문제는 그것이 currentScrollTol % 100 == 0을 만들기가 어렵다는 것입니다. 어떻게하면 정상적으로 변경할 수 있습니까 ??
Q2의 경우 "100 %"대신 "abs (tempScrollTop-currentScrollTop)> = 100"을 사용하여 정확한 100 경계에서 scrollTop을 치면 해당 게시물에 대해 – Dampsquid
네 감사합니다. 첫 번째 질문은, 내가 비동기 거짓으로 변경, 지금 어떤 시간 동안 브라우저를 차단 synchrous, 그 좋지 않아, 어떻게 스크롤 요청할 때 이중 요청없이 asynchrous 요청을 할 수 있습니까 ?? –
은 RequestInProgress boolean var를 사용하여 첫 번째 hasnt가 완료되는 동안 보내기 게시물을 막을 수 있습니다. – Dampsquid