栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

jquery实现分页切换

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

案例效果:

主要交互:

点击下面页码,选择对应页面的效果。点击向左向右的箭头,页面切到上一张或者下一张,当前页面是第一张时不能继续选择上一张,反之亦然。

实现代码如下: js:
pageControl('#img-change')
    // 切换消息页面
    function pageControl(id){
      // 箭头的展示
      function arrowShow(){
        if(currentIndex === pageLength - 1){
          $('.i-prev').removeClass('disable')
          $('.i-next').addClass('disable')
        }else if(currentIndex === 0){
          $('.i-prev').addClass('disable')
          $('.i-next').removeClass('disable')
        }else if(0< currentIndex < pageLength - 1){
          $('.i-prev').removeClass('disable')
          $('.i-next').removeClass('disable')
        }
      }
      var newsLi = $(id+' .news-group li')
      var pageLi = $(id+' .page-control li')
      var pageLength = pageLi.length
      var currentIndex = $(id+' .page-control li.active').index()
      if(currentIndex === 0){
        $('.i-prev').addClass('disable')
      }
      pageLi.on('click',function(){
        var index = $(this).index()
        $(this).addClass('active').siblings().removeClass('active')
        newsLi.eq(index).removeClass('hide').siblings().addClass('hide')
        currentIndex = index
        arrowShow()
      })
      // 上一张
      $('.i-prev').on('click',function(){
        if(currentIndex !== 0){
          var prevIndex = currentIndex - 1
          pageLi.eq(prevIndex).addClass('active').siblings().removeClass('active')
          newsLi.eq(prevIndex).removeClass('hide').siblings().addClass('hide')
          currentIndex = prevIndex
          arrowShow()
        }
      })
      // 下一张
      $('.i-next').on('click',function(){
        if(currentIndex !== pageLength - 1){
          var nextIndex = currentIndex + 1
          pageLi.eq(nextIndex).addClass('active').siblings().removeClass('active')
          newsLi.eq(nextIndex).removeClass('hide').siblings().addClass('hide')
          currentIndex = nextIndex
          arrowShow()
        }
      })
    }
html:










  • 1
  • 2
  • 3
  • 4
  • 5
css:
ul,ol{list-style: none;}
a{text-decoration: none;}
.img-change .popwin-main .con {overflow: initial;max-height: 600px;padding: 15px 20px 6px;}
*{margin: 0;padding:0;}
.hide{display: none;}
.img-change .popwin-main .con{overflow: initial;max-height: 600px;padding: 15px 20px 6px;}
.img-change .news-group{margin-bottom: 10px;}
.img-change .imgbox{width: 700px;height: 350px;background: #333333;border-radius: 4px;overflow: hidden;}
.img-change .imgbox img{width: 700px;height: 350px;}
.img-change .page-control .page-con{float: right;}
.img-change .page-control ul{float: left;height: 34px;}
.img-change .page-control .i-prev{cursor: pointer; display: block;float: left; width: 24px;height:24px;background: url(images/i-prev1.png) no-repeat center center;background-size: 8px 13px;}
.img-change .page-control .i-prev.disable{background: url(images/i-prev2.png) no-repeat center center;}
.img-change .page-control .i-next{cursor: pointer; display: block;float: left; width: 24px;height:24px;background: url(images/i-next1.png) no-repeat center center;background-size: 8px 13px;}
.img-change .page-control .i-next.disable{background: url(images/i-next2.png) no-repeat center center;}
.img-change .page-control ul li{cursor: pointer; width: 24px;float: left;margin-right: 2px; font-size: 12px;color: #999;height: 24px;background: none;border-radius: 2px;text-align: center;line-height: 24px;}
.img-change .page-control li.active,.img-news-pop .page-control li:hover{background: #F6F6F6;color: #666666;font-weight: bold;}
.img-change .btn-know{cursor: pointer; width: 81px;border: none;height: 32px;background: #3197FF;border-radius: 4px;}

向左向右的箭头如下:



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/992547.html

Java相关栏目本月热门文章

我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号