저는이 무한 스크롤 스크립트가 지난 8 시간 동안 작동하도록 노력해 왔으며 알아낼 수 없습니다.무한 스크롤에 문제가 있습니다.
여기에 사이트를 업로드하여 문제가 표시 될 수 있습니다.아래로 스크롤하면 article04, 03, 02을로드 한 다음 article01이 이미로드 된 이후 기사로드가 중지됩니다. 문제는 로딩을 멈추지 않는다는 것입니다 ... 그리고 콘솔에서 로깅 된 변수를 콘솔에서 추적하면 정말 놀라 울 것입니다. 나는 문제가 "범위"로 할 필요가 있다고 생각하지만 난 당신이
가 정말 감사 할 수 있다면 도와주세요
:-(확실하지 않다
$(document).ready(function() {
// DATABASE OF ARTICLES
var database = [
"article04",
"article03",
"article02",
"article01"
];
// THIS WHOLE SECTION CREATES THE INFINITE SCROLL EFFECT BY ACCESSING THE ARTICLES IN ORDER.
// IT'S NOT QUITE WORKING THOUGH.
// IF YOU FIGURE OUT THE BUGS, YOU CAN ACTIVATE INFINITE SCROLL!
// POST CODE ON STACKOVERFLOW... MAYBE YOU'LL GET SOME HELP!
// get initial page name
if (articleCounter == 0) {
var pathArray = window.location.pathname.split('/');
var pageName = pathArray[2];
console.log(pageName);
}
// initialize variables
var win = $(window);
var articleCounter = 0;
console.log(articleCounter);
// Each time the user scrolls
win.scroll(function() {
// End of the document reached?
if ($(document).height() - win.height() == win.scrollTop()) {
$('#loading').show();
// if this article is the next one in the list, skip it and go to next one
if (pageName == database[articleCounter]) {
articleCounter++;
var nextPage = database[articleCounter];
pageName = nextPage;
console.log(nextPage);
} else {
var nextPage = database[articleCounter];
pageName = nextPage;
console.log(nextPage);
}
// append nextPage to the end of the document
if (nextPage !== undefined) {
$.ajax({
url: '../' + nextPage + '/index.php',
dataType: 'html',
success: function(html) {
$('body').append(html);
$('#loading').hide();
articleCounter++;
console.log(articleCounter);
// POSSIBLE TO CHANGE URL PATH NAME HERE???
}
});
}
}
});
});
편집 :!
오늘 완전히 다시 작성했는데 여전히 똑같은 문제가 있습니다. 문제가 SCOPE와 관련 있다고 90 % 확신하지만 아직 해결하지 못했습니다. 아직 새 코드가 있습니다. 작동하지 않음 :
$ (문서) .ready (함수() {
// DATABASE OF ARTICLES
var database = [
"article04",
"article03",
"article02",
"article01"
];
var articleCounter = 0;
// get initial page name
var pathArray = window.location.pathname.split('/');
var initialPage = pathArray[2];
alert("Initial page is " + initialPage);
// when you scroll
$(window).scroll(function() {
// if you've reached the end of the document
if ($(document).height() - $(window).height() == $(window).scrollTop()) {
$('#loading').show();
// if you've reached the end of the database
if (articleCounter >= database.length) {
// load ending footer
alert("You've reached end of database! articleCounter is " + articleCounter);
// quit program
}
else if (database[articleCounter] == initialPage) {
articleCounter++;
appendArticle();
articleCounter++;
}
else {
appendArticle();
articleCounter++;
}
}
});
// end scroll function
function appendArticle() {
$.ajax({
url: '../' + database[articleCounter] + '/index.php',
dataType: 'html',
success: function(html) {
$('body').append(html);
$('#loading').hide();
// POSSIBLE TO CHANGE URL PATH NAME HERE???
}
});
}
빠른 답변을 보내 주셔서 감사합니다. 나는 당신의 편집을 시도했다. 그러나 그것은 작동하지 않았다 :-(나는 당신이 문제를 볼 수 있도록 여기에 사이트를 업로드했다. http://kevinellerton.com/meditationmagazine/article01/ 아래로 스크롤하면 article04, 03, 02, 그리고 article01이 이미로드 된 이후에 기사로드를 중지합니다. 문제는로드를 멈추지 않는다는 것입니다. 콘솔에서 변수를 추적하면 정말 놀랍습니다. –
@KevinEllerton이 신속하게 묻겠습니다. 이 무한 스크롤 전에로드 된 기사 1 및 모든 페이지가 스크롤 된 후 기사 1로 이동합니까 –
http://alvarotrigo.com/fullPage/examples/continuous.html 어쩌면 원하는 경우 .... –