jquery實現(xiàn)的偽分頁效果代碼
本文實例講述了jquery實現(xiàn)的偽分頁效果代碼。分享給大家供大家參考,具體如下:
這里介紹的jquery偽分頁效果,在火狐下表現(xiàn)完美,IE全系列下有些問題,引入了jQuery1.7.2插件,代碼里有豐富的注釋,相信對學習jQuery有不小的幫助,期待大家關注。
運行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/jquery-pic-mn-page-style-codes/
具體代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery偽分頁效果</title>
<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("ul li:gt(3)").hide();//初始化,前面4條數(shù)據(jù)顯示,其他的數(shù)據(jù)隱藏。
var total_q=$("ul li").index()+1;//總數(shù)據(jù)
var current_page=4;//每頁顯示的數(shù)據(jù)
var current_num=1;//當前頁數(shù)
var total_page= Math.round(total_q/current_page);//總頁數(shù)
var next=$(".next");//下一頁
var prev=$(".prev");//上一頁
$(".total").text(total_page);//顯示總頁數(shù)
$(".current_page").text(current_num);//當前的頁數(shù)
//下一頁
$(".next").click(function(){
if(current_num==7){
return false;//如果大于總頁數(shù)就禁用下一頁
}
else{
$(".current_page").text(++current_num);//點擊下一頁的時候當前頁數(shù)的值就加1
$.each($('ul li'),function(index,item){
var start = current_page* (current_num-1);//起始范圍
var end = current_page * current_num;//結(jié)束范圍
if(index >= start && index < end){//如果索引值是在start和end之間的元素就顯示,否則就隱
$(this).show();
}else {
$(this).hide();
}
});
}
});
//上一頁方法
$(".prev").click(function(){
if(current_num==1){
return false;
}else{
$(".current_page").text(--current_num);
$.each($('ul li'),function(index,item){
var start = current_page* (current_num-1);//起始范圍
var end = current_page * current_num;//結(jié)束范圍
if(index >= start && index < end){//如果索引值是start和end之間的元素就顯示,否則就隱藏
$(this).show();
}else {
$(this).hide();
}
});
}
})
})
</script>
<style type="text/css">
.main{width:800px;zoom:1;margin:0 auto;}
.item{width:800px;overflow:hidden;}
ul{padding:0;width:860px;zoom:1;}
.clear{zoom:1;}
.clear:after{content:"";display:block;height:0;clear:both;visibility:hidden;}
ul li{list-style-type:none;float:left;background:#F69;font-size:60px;text-shadow:1px 1px 3px #555;width:380px;height:200px;margin:10px 40px 10px 0;line-height:200px;text-align:center;color:#fff;}
.page_btn{padding-top:20px;}
.page_btn a{cursor:pointer;padding:5px;border:solid 1px #ccc;font-size:12px;}
.page_box{float:right;}
.num{padding:0 10px;}
</style>
</head>
<body>
<div class="main">
<div class="item">
<ul class="clear">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
<li>21</li>
<li>22</li>
<li>23</li>
<li>24</li>
<li>25</li>
<li>26</li>
<li>27</li>
<li>28</li>
</ul>
</div>
<div class="page_btn clear">
<span class="page_box">
<a class="prev">上一頁</a><span class="num"><span class="current_page">1</span><span style="padding:0 3px;">/</span><span class="total"></span></span><a class="next">下一頁</a>
</span>
</div>
</div><!--main-->
</body>
</html>
希望本文所述對大家jQuery程序設計有所幫助。
相關文章
淺析jQuery(function(){})與(function(){})(jQuery)之間的區(qū)別
本篇文章主要是對jQuery(function(){})與(function(){})(jQuery)之間的區(qū)別進行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助2014-01-01
jQuery的Ajax接收java返回數(shù)據(jù)方法
今天小編就為大家分享一篇jQuery的Ajax接收java返回數(shù)據(jù)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08
jQuery 可以拖動的div實現(xiàn)代碼 腳本之家修正版
最近研究了一下jQuery,覺得真的是一個很不錯的js庫,其他的不說,關鍵是有翔實的文檔,這點是非常關鍵的。2009-06-06
jQuery 3.0 的 setter和getter 模式詳解
這篇文章主要介紹了jQuery 3.0 的 setter和getter 模式詳解的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-07-07

