简体   繁体   English

jQuery 滚动到页面底部时加载内容

[英]jQuery load content when scroll to bottom of page

i need to do when i'm scrolling down of my page load more当我向下滚动我的页面加载更多时我需要做的

<div class="container">
<div class="news">News 1</div>
<div class="news">News 2</div>
<div class="news">News 3</div>
<div class="news">News 4</div>
</div>

i have only html site, no PHP and MySQL, all news are i one page.我只有html网站,没有PHP和MySQL,所有新闻都是一页。 for example when scroll to bottom for 500 px, load more content例如,当滚动到底部 500 像素时,加载更多内容

I think that you would do it better with a Lazy Load plugin in Javacript.我认为使用 Javacript 中的延迟加载插件会做得更好。

But simpliest way to implement what you want is using Jquery following this steps:但实现您想要的最简单方法是按照以下步骤使用 Jquery:

1 - Calculating de Window Vertical size (on document ready) 1 - 计算 de Window 垂直尺寸(准备好文档)

var element = $(window).height();

2 - Calculating Scroll and counterweigh with the element page 2 - 用元素页面计算滚动和平衡

$(window).scroll(function(){
  var y = $(window).scrollTop();
    if (y >= element){
      // Do stuff, like append more elements
    }
});

If you are seeking for lazy load this is a good step-by-step tutorial on how to get it on your website.如果您正在寻找延迟加载,是一个关于如何在您的网站上获得它的很好的分步教程。 I have done it on my website in no time.我很快就在我的网站上完成了。

The correct code for this is:正确的代码是:

 $(document).ready(function(){ var element = $(document).height(); $(window).scroll(function(){ var y = parseInt($(window).scrollTop()) + parseInt($(window).height()); if (y >= element){ $("#loader_bars").show(); //Make post to server from last id recieved } }); });

Its bug free, I used all the time.....Also the lazyload the Mirakurun said is just for images它没有错误,我一直在使用.....另外,Mirakurun 所说的 lazyload 仅适用于图像

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

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