简体   繁体   English

如何在HTML上制作无限滚动图片页面?

[英]How to make an infinite Scroll images page on HTML?

I want to create an HTML page that i can put few images inside, and scroll (up and down, right to left), without limits (the images will return themselves). 我想创建一个HTML页面,我可以在其中放置几张图像,然后无限制地滚动(上下左右从右到左)(图像将自行返回)。

Here is great example for this: MacDonalds Favourites . 这是一个很好的例子: MacDonalds收藏夹

i've tried to do a js code that calcuate the height of the page and when he now that he came to the end of tha page - he scrolling to the top of him. 我试图做一个js代码来计算页面的高度,当他现在来到页面的末尾时-他滚动到他的顶部。

$(window).scroll(function() { 
    if($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
        window.scrollTo(0,0); 
    } 
});

The infinite scroll method does invoke jQuery, similar to what you have written here. 无限滚动方法确实会调用jQuery,类似于您在此处编写的内容。 But you would also want to bring in additional data to be displayed, which you can do in a variety of different ways. 但是,您还希望引入要显示的其他数据,您可以采用多种不同的方式进行处理。

Since you are already using jQuery, it would sense to use the .ajax() method from that library. 由于您已经在使用jQuery,因此可以使用该库中的.ajax()方法。

$.ajax({
  url: "http://your-url-here.com/extra-content.html",
}).done(function(html)  {
  $("#results").append(html); 
});

See the jQuery docs for more information on the .ajax method: https://api.jquery.com/jQuery.ajax/ 有关.ajax方法的更多信息,请参见jQuery文档: https : //api.jquery.com/jQuery.ajax/

尝试将iscroll与无限滚动一起使用,我建议您也对图像使用对齐元素,以使其具有轮播外观http://iscrolljs.com/#infinite-scrolling

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM