无刷新动态加载数据 滚动条加载适合评论等页面

前端之家收集整理的这篇文章主要介绍了无刷新动态加载数据 滚动条加载适合评论等页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

滚屏加载更多数据,适合评论页面 本例的数据库很简单,一看就明了

<IMG src="https://files.jb51.cc/file_images/article/201310/201310161717332.gif?201391617182"&gt;

<div class="codetitle"><a style="CURSOR: pointer" data="65192" class="copybut" id="copybut65192" onclick="doCopy('code65192')"> 代码如下:
<div class="codebody" id="code65192">
<div id="container"> <?PHP
$query=MysqL_query("select from content order by id desc limit 0,10");
while ($row=MysqL_fetch_array($query)) {
?>
<div class="single_item">
<div class="element_head">
<div class="date"><?php echo date('m-d H:i',strtotime($row['updatetime']));?>

<div class="author"><?php echo $row['id'];?>


<div class="content"><?php echo $row['message'];?>


<?php } ?>

<div class="nodata">

js文件
<div class="codetitle"><a style="CURSOR: pointer" data="56906" class="copybut" id="copybut56906" onclick="doCopy('code56906')"> 代码如下:<div class="codebody" id="code56906">
<script type="text/javascript">
$(function(){
var winH = $(window).height(); //页面可视区域高度
var i = 1;
$(window).scroll(function () {
var pageH = $(document.body).height();
var scrollT = $(window).scrollTop(); //滚动条top
var aa = (pageH-winH-scrollT)/winH;
if(aa<0.02){
$.getJSON("result.PHP",{page:i},function(json){
if(json){
var str = "";
$.each(json,function(index,array){
var str = "<div class=\"single_item\"><div class=\"element_head\">";
var str = str + "<div class=\"date\">"+array['date']+"";
var str = str + "<div class=\"author\">"+array['author']+"";
var str = str + "<div class=\"content\">"+array['content']+"";
$("#container").append(str);
});
i++;
}else{
$(".nodata").show().html("别滚动了,已经到底了。。。");
return false;
}
});
}
});
});


result.PHP
<div class="codetitle"><a style="CURSOR: pointer" data="34880" class="copybut" id="copybut34880" onclick="doCopy('code34880')"> 代码如下:<div class="codebody" id="code34880">
<?PHP
include("conn.PHP"); $page = intval($_GET['page']); //获取请求的页数
$start = $page
5;
$query=MysqL_query("select * from content order by id desc limit $start,5");
while ($row=MysqL_fetch_array($query)) {
$arr[] = array(
'content'=>$row['message'],
'author'=>$row['id'],
'date'=>date('m-d H:i',strtotime($row['updatetime']))
);
}
echo json_encode($arr); //转换为json数据输出
?>

原文链接:/php/25599.html
动态加载无刷新滚动条滚动条

猜你在找的PHP相关文章