旭改のページコード

2634 ワード

/**
	 *   :              
	 * @param curPage      
	 * @param totalPage       
	 * @param clickHandler     ,          
	 * @param barCount            
	 */
	$.fn.pagination = function(curPage, totalPage, clickHandler, barCount){
		var pageBarNum = 5;
		if(barCount){
			pageBarNum = barCount;
		}
		var tar = $(this).addClass("pagination");
		var start = 1;
		var end = totalPage;
		if(totalPage > pageBarNum){
			var index = Math.floor(pageBarNum/2);
			var start = (curPage-index) > 0 ? (curPage-index) : 1;
			if(totalPage - start <= pageBarNum){
				start = totalPage - pageBarNum + 1;
			}
			var end = start + pageBarNum;
		}
		var pageHtml = "";
		if(curPage > 1){
			pageHtml += "<a p='" + (curPage - 1) + "'>«</a>";
		}else{
			pageHtml += "<a class='disabled'>«</a>";
		}
		for (var i = start; i < end; i++) {
			if (i > totalPage)
				break;
			if (i == curPage) {
				pageHtml += '<a class="disabled">' + i + '</a>';
			} else {
				pageHtml += "<a p='" + i + "'>" + i + "</a>";
			}
		}

		if(curPage < totalPage){
			pageHtml += "<a p='" + (curPage + 1) + "'>»</a>";
		}else{
			pageHtml += "<a class='disabled'>»</a>";
		}
		tar.html(pageHtml);
		if(clickHandler){
			tar.find("a[p]").bind("click", function(){
				var page = $(this).attr("p");
				clickHandler(page);
			});
		}
	}
	

  :
.pagination{
	display: inline-block;
}
.pagination a{
	display: inline-block;
	float: left;
	padding: 0 14px;
	line-height: 38px;
	text-align: center;
	border-width: 1px 1px 1px 0px;
	border-style: solid;
	border-color: #ccc;
	font-size:14px;
}
.pagination a:first-child{
	border-radius: 3px 0 0 3px;
	border-left: 1px solid #ccc;
}
.pagination a:last-child{
	border-radius: 0 3px 3px 0;
}
.pagination a:hover{
	background-color: whiteSmoke;
	text-decoration: none;
}
.pagination .disabled{
	background-color: whiteSmoke;
	color: #999;
	cursor: default;
}
  <[email protected]>  15:49:47