天天看点

php 无限滚动加载,jquery+ajax+php创建无限滚动页面

jquery+ajax+php创建无限滚动页面

html文件:

Endless Scroll

body{ font-family: "Trebuchet MS",verdana,arial;}

#loading{ display:none; font-weight:bold;color:#FF0000;}

p { padding:10px;}

Test Paragraph 1

Test Paragraph 2

Test Paragraph 3

loading data...

$(document).ready(function()

{

$(window).scroll(loadData);

});

var counter = 0;

function loadData()

{

if(counter < 5)

{

if (isUserAtBottom())

{

getData();

}

}

}

function isUserAtBottom()

{

return ((($(document).height() - $(window).height()) - $(window).scrollTop()) <= 50) ? true : false;

}

function getData()

{

$(window).unbind('scroll');

$('#loading').show();

$.get(

'data.php',

{},

function(response)

{

counter++;

$('#loading').hide();

$('#container').append(response);

$(window).scroll(loadData);

});

}

data.php文件:

echo '

This data has been

loaded from server...

';

?>