[英]Show more button on Infinite Scroll
I am trying to set up a show more button to start the infinite scroll. 我正在尝试设置显示更多按钮以开始无限滚动。 Once the button is clicked it should infinite scroll until the end. 单击按钮后,它应无限滚动直到结束。
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();
});
But for some reason with this code the ajax success function gets called twice and the results get appended twice. 但是由于某种原因,此代码会两次调用ajax成功函数,并将结果附加两次。 Is there something i'm doing wrong or is there a better way to set this up? 我有做错什么吗,还是有更好的方法进行设置?
I figured it out, it was the var scrolltrigger = 0.95; 我知道了,那是var scrolltrigger = 0.95; Something about the height was causing it to run twice. 关于高度的某种信息使它运行两次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.