0
무한 스크롤을 시작하려면 더 많은 버튼을 표시하려고합니다. 버튼을 클릭하면 끝까지 무한대로 스크롤해야합니다.무한 스크롤에 더 많은 버튼 표시
function infiniteScroll() {
var postHolder = document.getElementById('postHolder');
var articleCount = postHolder.getElementsByTagName('article').length + 1;
$.ajax({
url: "/handlers/InfiniteScroll.ashx?page=" + articleCount + "",
contentType: "text/html; charset=utf-8",
dataType: "html",
success: function (data) {
if (data != "") {
$('.posts-holder .article:last').after(data);
}
}
});
};
$("#showMore").click(function() {
infiniteScroll();
$(window).scroll(function() {
var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
var scrolltrigger = 0.95;
if (((wintop/(docheight - winheight)) > scrolltrigger) && test == 1) {
infiniteScroll();
}
});
$('#showMore').hide();
});
그러나이 코드를 사용하면 ajax success 함수가 두 번 호출되고 결과가 두 번 추가됩니다. 내가 잘못하고있는 것이 있거나 이것을 설정하는 더 좋은 방법이 있습니까?
'# showMore'는 앵커 태그입니까? 그것을 클릭하면 창이 스크롤되어 창 스크롤 이벤트가 발생하고'infiniteScroll()'이 실행됩니까? –
그냥 입력 태그. 감사합니다 – user973671
– user973671