js css自定义分页效果
半块菠萝 人气:0网上看了好多分页插件都不太满意,所以根据网上的一些东西自己做了一个,可以搭配mvc和数据库
效果图片
先来css(样式不喜欢的话可以不用这个)
.pagelist {padding:10px 0; text-align:center;} .pagelist span,.pagelist a{ border-radius:3px; border:1px solid #dfdfdf;display:inline-block; padding:5px 12px;} .pagelist a{ margin:0 3px;} .pagelist span.current{ background:#09F; color:#FFF; border-color:#09F; margin:0 2px;} .pagelist a:hover{background:#09F; color:#FFF; border-color:#09F; } .pagelist label{ padding-left:15px; color:#999;} .pagelist label b{color:red; font-weight:normal; margin:0 3px;} .popup { display: none; list-style-type: none; overflow: hidden; position: absolute; } /*显示弹出菜单*/ .popupmenu li:hover ul { display: block; z-index:2; /*left:840px;*/ } .popupmenu li ul:hover { display: block; z-index:2; /*left:840px;*/ }
html 需要引用jquary
<div class="pagelist" style="margin-top:500px"> <ul class="popupmenu"> <li> <a href="p.url?page=1" rel="external nofollow" >首页</a> <a href="p.url?page=p.up" rel="external nofollow" >上一页</a> <a id="pop" href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" onclick="popup()">1/2</a> <ul id="popup" class="popup"> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >1/2</a> </li> <li> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >2/2</a> </li> </ul> <a href="p.url?page=p.next" rel="external nofollow" >下一页</a> <a href="p.url?page=p.sum" rel="external nofollow" >尾页</a> </li> </ul> </div>
js
<script type="text/javascript"> // 获取id为pop的元素的位置 var popX = $('#pop').offset().left; // alert($('#pop').height()); var popY = $('#pop').offset().top; var lineheight = $('#pop').height(); var linumber = $('#popup li').length; // alert(lineheight); // 设置id为popup元素的位置 $("#popup").css({ "position": "fixed", "top": (popY - (linumber * 27.5)) + "px", "left": (popX - 23) + "px", "line-height": lineheight + "px" }); </script>
分页的类
public partial class page { // 当前页 public int pagenow { get; set; } // 总页数 public int sum { get; set; } // 地址 public string url { get; set; } // 上一页 public int up { get; set; } // 下一页 public int next { get; set; } }
想要使用的话,在控制器获取数据,替换掉html上的相应位置就行了。
加载全部内容