<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
li {
list-style: none;
}
div.paging {
position: absolute;
bottom: 50px;
left: 50%;
margin-left: -200px;
height: 28px;
width: 400px;
}
div.paging > span {
display: block;
width: 26px;
height: 26px;
border: 1px solid #999;
cursor: pointer;
float: left;
}
div.paging span.prev {
margin-right: 4px;
background: url(../img/prevbtn.png) center no-repeat;
}
div.paging span.next {
margin-left: 4px;
background: url(../img/nextbtn.png) center no-repeat;
}
div.paging div.page-btn {
width: 180px;
height: 28px;
overflow: hidden;
float: left;
position: relative;
}
div.paging div.page-btn ul {
width: 1000px;
height: 28px;
position: absolute;
left: 0;
top: 0;
}
div.paging div.page-btn ul li {
float: left;
height: 26px;
line-height: 28px;
padding: 0 6px;
font-size: 20px;
color: #666;
cursor: pointer;
}
div.paging div.page-btn ul li.active {
border-bottom: 2px solid #9ACD32;
}
</style>
</head>
<body>
<div class="paging">
<span class="prev"></span>
<div class="page-btn">
<ul class="btn-list">
<li class="active">2016</li>
<li>2015</li>
<li>2014</li>
<li>2013</li>
<li>2012</li>
<li>2011</li>
<li>2010</li>
<li>2009</li>
</ul>
</div>
<span class="next"></span>
</div>
</body>
<script type="text/javascript" src="js/jquery.js" ></script>
<script type="text/javascript">
$(function(){ /*
wrap:最外层的dom
prev:上一页的按钮
next:下一页的按钮
btnWrap:分页器的页数的外层dom,注意:这个dom不包含prev和next
btnBox:每个分页点的dom外层
btn:分页点的dom
showBtn:展示个数,默认为3个
* */ createPage({
wrap:'.paging',
prev:'.prev',
next:'.next',
btnWrap:'.page-btn',
btnBox:'.btn-list',
btn:'li',
showBtn:4,
callback:function(num){
console.log(num);
}
}); function createPage(option){
var fn = {};
var $wrap =$(option.wrap),
$prev = $wrap.find(option.prev),
$next = $wrap.find(option.next),
$btnWrap = $wrap.find(option.btnBox),
$btnList = $btnWrap.find(option.btn),
currActive = 0,
prevActive = 0,
maxLen = $btnList.length,
showBtn = option.showBtn || 3,
btnWidth = $btnList.outerWidth(),
currLeft = 0;
//调节宽度
$wrap.find(option.btnWrap).css("width",showBtn*btnWidth); //绑定上一个事件
$prev.on("click",function(){
currActive--;
if(currActive < 0){
currActive = maxLen-1;
}
fn.changed(currActive);
}); //绑定下一个事件
$next.on("click",function(){
currActive++;
if(currActive >= maxLen){
currActive = 0;
}
fn.changed(currActive); }); //修改
fn.changed = function(index){
if(prevActive > index){
fn.slideBtn(index-1);
}else{
fn.slideBtn(index);
}
$btnList.eq(index).addClass("active").siblings().removeClass("active");
if(option.callback){
option.callback($btnList.eq(index).html());
}
prevActive = index;
}; //项目绑定
$btnWrap.on("click","li",function(){
currActive = $(this).index();
fn.changed(currActive);
});
fn.slideBtn = function(index){
currLeft = index;
if(index < showBtn-1 ){
currLeft = 0;
} if(maxLen-index < showBtn ){
currLeft = maxLen - showBtn;
}
$btnWrap.stop(true,true).animate({"left":currLeft*btnWidth*(-1)},500);
}; return fn;
} });
</script>
</html>

  

js分页器插件的更多相关文章

  1. 原生js分页器插件

    window.page = function page(ele, para) { this.ele = document.querySelector(ele); this.options = { co ...

  2. Sublime Text 2 JS 格式化插件 JsFormat的配置使用

    (转自http://www.jb51.net/softjc/178401.html) 这里下载这插件包 https://github.com/jdc0589/JsFormat ,点油下角的zip就能下 ...

  3. Django 的css和js压缩插件:django_compressor

    今天尝试了django_conpressor,一个在django框架中压缩css和js的插件,灰常有用 我把它加载在我的base的HTML template中,原来未经压缩的css和js是: < ...

  4. knob.js进度插件

    关于knob.js进度插件的使用 关于这个插件,妹的,第一次使用坑死爹了,各种不会,幸亏我有持之以恒的精神,最终还是让其臣服于我的胯下.... 1.  引入 head  部分添加knob.js,同时引 ...

  5. Sublime Text 2 JS 格式化插件 JsFormat

    这里下载这插件包 https://github.com/jdc0589/JsFormat ,点油下角的zip就能下载插件包放到sublime安装目录的DataPackages目录中重新打开sublim ...

  6. Notyf - 超级简单、响应式的 JS 通知插件

    通知是网站的常用功能之一,可以用来显示消息.通告.提示等等.Notyf 是一款超级简单.响应式的 JS 通知插件,不依赖 jQuery 库,可以独立使用.赶紧试用一下吧! 在线演示      免费下载 ...

  7. js开关插件使用

    一.简介 本篇文章介绍一个比较好使用的js开关插件Switchery,该插件的样式是ios7的滑动按钮插件,并且将很多功能加入到配置项,简单.灵活,支持的绝大部分浏览器(Chrome, Firefox ...

  8. js写插件教程深入

    原文地址:https://github.com/lianxiaozhuang/blog 转载请注明出处 js 写插件教程深入 1.介绍具有安全作用域的构造函数 function Fn(name){ t ...

  9. move.js运动插件

    move.js 运动插件是一款针对元素动画效果的插件.可以运用此插件制作出各类元素效果. 插件GitHub地址:https://github.com/visionmedia/move.js 下面整理学 ...

随机推荐

  1. Servlet3.0 multipart 文件上传技术

    Servlet3.0 javaConfig配置 传统的servlet都是在web.xml中配置,从Servlet 3.0开始提供了ServletContainerInitializer接口,允许使用代 ...

  2. VMWARE虚拟机不显示主机共享的文件夹解决办法

    执行如下命令重新配置,不用重启. #sudo vmware-config-tools.pl

  3. CH6201 走廊泼水节【最小生成树】

    6201 走廊泼水节 0x60「图论」例题 描述 [简化版题意]给定一棵N个节点的树,要求增加若干条边,把这棵树扩充为完全图,并满足图的唯一最小生成树仍然是这棵树.求增加的边的权值总和最小是多少. 我 ...

  4. php实现简单消息发送+极光推送系统

    前几天刚写完的一个东西,写的比较简单,没有使用其他插件,原生php+计划任务实现 极光推送的代码 /* $receiver="registration_id" : [ " ...

  5. let 与 const 的用法

    let 与 const 的用法 let 用来声明变量,并且会在当前作用域形成 代码块 conts 用来声明常量,所谓常量就是物理指针不可以更改的变量. 所谓代码块,最简单的做法就是(这个 {} 就是一 ...

  6. java mvc spring boot

    spring mvchttp://www.cnblogs.com/wcf6676/p/5333352.html 利用mybatis-generator自动生成代码http://www.cnblogs. ...

  7. CS231n: Convolutional Neural Networks for Visual Recognition

    https://zhuanlan.zhihu.com/p/28522637 https://zhuanlan.zhihu.com/p/21930884 mark

  8. Java、mysql、html、css、js 注释&大小写

    java三种注释 原文链接:https://www.cnblogs.com/miys/p/4bf714ce33068dcf9ac6526309c9b5e6.html 单行注释:// 注释内容 多行注释 ...

  9. ORACLE UNDO

    UNDO 数据操纵 数据操纵语言(DML)由以下SQL语句组成: INSERT,DELETE,UPDATE,MERGE DML始终作为事务处理的一部分执行,它可以: 使用Rollback命令执行回退 ...

  10. LeetCode 929 Unique Email Addresses 解题报告

    题目要求 Every email consists of a local name and a domain name, separated by the @ sign. For example, i ...