生活随笔
收集整理的這篇文章主要介紹了
滚动加载更多内容
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本例與《無刷新動態加載數據,滾動條加載》功能是相同的,自己查看用哪個更好.
數據庫很簡單content表 字段id和message
演示 ?
XML/HTML Code <?php??include_once('../../conn.php');??????$last_msg_id=$_GET['last_msg_id'];??$action=$_GET['action'];????if($action?<>?"get")??{???>????<link?rel="stylesheet"?href="css.css"?type="text/css"?/>??<script?type="text/javascript"?src="../../js/jquery-1.9.1.min.js"></script>????????????<script?type="text/javascript">??????$(document).ready(function(){????????????????????????function?last_msg_funtion()???????????{???????????????????????????var?ID=$(".message_box:last").attr("id");??????????????$('div#last_msg_loader').html('<img?src="bigLoader.gif">');??????????????$.post("index.php?action=get&last_msg_id="+ID,????????????????????????????function(data){??????????????????if?(data?!=?"")?{??????????????????$(".message_box:last").after(data);???????????????????????????}??????????????????$('div#last_msg_loader').empty();??????????????});??????????};??????????????????????$(window).scroll(function(){??????????????if??($(window).scrollTop()?==?$(document).height()?-?$(window).height()){?????????????????last_msg_funtion();??????????????}??????????});?????????????????});??????????????????</script>??<link?rel="stylesheet"?type="text/css"?href="../demo.css">??</head>??<body>????<div?align="center">??<?php????include('load_first.php');?????>??<div?id="last_msg_loader"></div>??</div>????</div>??</body>??</html>??????<?php??}??else??{?????include('load_second.php');?????????????????????}???>?????????????? ?load_first.php
PHP Code <?php??$sql=mysql_query("SELECT?*?FROM?content?ORDER?BY?id?DESC?LIMIT?15");??while($row=mysql_fetch_array($sql))??????????{??????????$msgID=?$row['id'];??????????$msg=?$row['message'];?????>??<div?id="<?php?echo?$msgID;??>"??align="left"?class="message_box"?>??<span?class="number"><?php?echo?$msgID;??></span><?php?echo?$msg;??>???</div>????<?php??}???>?? load_second.php
PHP Code <?php??$last_msg_id=$_GET['last_msg_id'];???$sql=mysql_query("SELECT?*?FROM?content?WHERE?id?<?'$last_msg_id'?ORDER?BY?id?DESC?LIMIT?5");???$last_msg_id="";????????????while($row=mysql_fetch_array($sql))??????????{??????????$msgID=?$row['id'];??????????$msg=?$row['message'];???????>????????????????????<div?id="<?php?echo?$msgID;??>"??align="left"?class="message_box"?>??<span?class="number"><?php?echo?$msgID;??></span><?php?echo?$msg;??>???</div>??????????????<?php??}???>?? ?
原文地址:http://www.freejs.net/article_jquerywenzi_86.html
?
總結
以上是生活随笔為你收集整理的滚动加载更多内容的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。