简体   繁体   English

在页面中创建无尽的可滚动div

[英]Creating an endless scrollable div in a page

I'm trying to create an endless scrollable div in my page. 我正在尝试在页面中创建一个无尽的可滚动div。 To do so I'm trying to use the following code --> http://jsfiddle.net/cyrus2013/Qq85d/ 为此,我尝试使用以下代码-> http://jsfiddle.net/cyrus2013/Qq85d/

$(document).ready(function(){

function lastAddedLiveFunc()
{
    $('div#lastPostsLoader').html('<img src="../bigLoader.gif">');

    $.get("loadmore.php", function(data){
        if (data != "") {
            //console.log('add data..');
            $(".items").append(data);
        }
        $('div#lastPostsLoader').empty();
    });
};

//lastAddedLiveFunc(); // lastAddedLiveFunc(); $(window).scroll(function(){ $(窗口).scroll(函数(){

  var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
  var  scrolltrigger = 0.95;

  if  ((wintop/(docheight-winheight)) > scrolltrigger) {
     //console.log('scroll bottom');
     lastAddedLiveFunc();
  }

}); }); }); });

But, here the code is for creating the same for an entire page (window) where as I need to create it for a specific 'div' in a webpage. 但是,这里的代码是为整个页面(窗口)创建相同的代码,而我需要为网页中的特定“ div”创建代码。

In this part of the page I have difficulty figuring out the dimensions of the 'div'. 在页面的这一部分,我很难弄清“ div”的尺寸。

var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height();
      var  scrolltrigger = 0.95;

A similar thing would the "Ticker" section on Facebook on the right side of the page, which tells us what our friends are doing in real time. 与之类似的是,页面右侧Facebook上的“ Ticker”部分,它告诉我们我们的朋友实时在做什么。

Please help me in figure out the code for this requirement... Thanks in advance! 请帮助我找出此要求的代码...预先感谢!

How about this (the randomPara stuff is there only to simulate the content): 怎么样(randomPara内容仅用于模拟内容):

DEMO DEMO

var scroller;
var initContents = 10;
var shown = 0;
var content = [];

function init(){
 var scroller = document.getElementById('scroller');
 for(var i=0;i<100;i++){
  var randomPara = "";
  var words = Math.floor(Math.random()*100);
  for(var j=0;j<words;j++) randomPara += "word ";
  content.push(randomPara+"<br>");
 }
 for(var i=0;i<initContents;i++){
  scroller.innerHTML += content[shown];
  shown++;
 }
 scroller.onscroll = function(){
  if(shown < content.length) if(this.scrollTop >= this.scrollHeight-this.clientHeight)
   scroller.innerHTML += content[shown];
   shown++;
 }
}

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

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