jQuery实现常见的隐藏与展示列表效果示例


Posted in jQuery onJune 04, 2018

本文实例讲述了jQuery实现常见的隐藏与展示列表效果。分享给大家供大家参考,具体如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>3water.com jquery品牌列表效果</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel=" rel="external nofollow" stylesheet">
<style>
  *{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -moz-box-sizing: border-box;
  }
  body {
    font: 16px/20px "Microsoft yahei,'微软雅黑'"
    color: #fff;
  }
  ul {
    list-style-type:none;
  }
  a {
    text-decoration: none;
    color: #000;
  }
  ul li {
    float: left;
    text-align: right;
  }
  .clear:before,.clear:after {
    content: "";
    clear: both;
    display: table;
    height: 0;
    overflow: hidden;
    zoom: 1;
  }
  .SubCategoryBox {
    width: 473px;
    margin: 0 auto;
    border: 1px solid;
  }
  .SubCategoryBox ul{
    padding: 5px 10px;
  }
  .SubCategoryBox ul li {
    padding: 5px;
  }
  .SubCategoryBox ul li:nth-child(3n-2) {
    width: 130px;
  }
  .SubCategoryBox ul li:nth-child(3n-1) {
    width: 161px;
    margin-right: 30px;
  }
  .SubCategoryBox ul li:nth-child(3n) {
    width: 130px;
  }
  .showmore {
    text-align: center;
  }
  .showmore a {
    background: #eef;
    color: #CFCFE0;
  }
  .hightlight a,.hightlight i {
    color: red;
    /* font-weight: bold; */
  }
</style>
</head>
<body>
    <div class="SubCategoryBox">
      <ul class="clear" id="bancon">
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >佳能</a><i>(30441)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >索尼</a><i>(30442)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >三星</a><i>(30443)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >尼康</a><i>(30444)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >松下</a><i>(30445)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >卡西欧</a><i>(30446)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >富士</a><i>(30447)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >柯达</a><i>(30448)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >宾得</a><i>(30449)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >理光</a><i>(30450)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >奥斯巴林</a><i>(30451)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >明基</a><i>(30452)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >爱国者</a><i>(30453)</i></li>
        <li><a href="javascript:" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >其他品牌相机</a><i>(30454)</i></li>
      </ul>
      <div class="showmore" id="showpp">
      <a href=""><span>显示全部品牌</span></a>
      </div>
    </div>
   <script src="http://cdn.bootcss.com/jquery/2.1.0/jquery.js"></script>
   <script>
   $(function(){
    var $target=$("#bancon li:gt(5):not(:last)");
    $target.hide();
    var $toggleBtn=$("#showpp a");
    $toggleBtn.click(function(){
      if($target.is(":visible")){
      $target.hide();
      $(this).find("span").text("显示所有品牌");
      $("ul li").removeClass('hightlight')
      }
      else {
        $target.show();
        $(this).find('span').text("精简显示品牌");
        $("ul li").filter(":contains('佳能'),:contains('尼康'),:contains('奥斯巴林')").addClass('hightlight')
      }
      return false;  /*阻止a标签的跳转*/
    });
   });
   </script>
</body>
</html>

使用在线HTML/CSS/JavaScript代码运行工具 http://tools.3water.com/code/HtmlJsRun测试效果如下:

jQuery实现常见的隐藏与展示列表效果示例

希望本文所述对大家jQuery程序设计有所帮助。

jQuery 相关文章推荐
jQuery轻松实现无缝轮播效果
Mar 22 jQuery
jQuery获取table下某一行某一列的值实现代码
Apr 07 jQuery
用户管理的设计_jquery的ajax实现二级联动效果
Jul 13 jQuery
基于jquery实现多选下拉列表
Aug 02 jQuery
基于JQuery的Ajax方法使用详解
Aug 16 jQuery
jQuery中的类名选择器(.class)用法简单示例
May 14 jQuery
jQuery阻止事件冒泡实例分析
Jul 03 jQuery
jQuery实现的监听导航滚动置顶状态功能示例
Jul 23 jQuery
详解jquery和vue对比
Apr 16 jQuery
JQuery常见节点操作实例分析
May 15 jQuery
jQuery 查找元素操作实例小结
Oct 02 jQuery
JavaScript或jQuery 获取option value值方法解析
May 12 jQuery
jQuery实现的简单获取索引功能示例
Jun 04 #jQuery
JS与jQuery实现ListBox上移,下移,左移,右移操作功能示例
May 31 #jQuery
jQuery基于Ajax实现读取XML数据功能示例
May 31 #jQuery
jQuery实现动态加载select下拉列表项功能示例
May 31 #jQuery
webpack里使用jquery.mCustomScrollbar插件的方法
May 30 #jQuery
jQuery 导航自动跟随滚动的实现代码
May 30 #jQuery
jQuery实现图片上传预览效果功能完整实例【测试可用】
May 28 #jQuery
You might like
javascript学习笔记(五) Array 数组类型介绍
2012/06/19 Javascript
javascript中的undefined和not defined区别示例介绍
2014/02/26 Javascript
SyntaxHighlighter 3.0.83使用笔记
2015/01/26 Javascript
js实现使用鼠标拖拽切换图片的方法
2015/05/04 Javascript
浅谈JavaScript前端开发的MVC结构与MVVM结构
2016/06/03 Javascript
详解BootStrap中Affix控件的使用及保持布局的美观的方法
2016/07/08 Javascript
JavaScript实现简单生成随机颜色的方法
2017/09/21 Javascript
jQuery响应滚动条事件功能示例
2017/10/14 jQuery
微信小程序利用swiper+css实现购物车商品删除功能
2019/03/06 Javascript
vue 搭建后台系统模块化开发详解
2019/05/01 Javascript
jQuery控制input只能输入数字和两位小数的方法
2019/05/16 jQuery
ajax跨域访问遇到的问题及解决方案
2019/05/23 Javascript
vue在线动态切换主题色方案
2020/03/26 Javascript
[16:19]教你分分钟做大人——风暴之灵
2015/03/11 DOTA
python sys模块sys.path使用方法示例
2013/12/04 Python
日常整理python执行系统命令的常见方法(全)
2015/10/22 Python
Python中几种导入模块的方式总结
2017/04/27 Python
Python基于Tkinter模块实现的弹球小游戏
2018/12/27 Python
使用Template格式化Python字符串的方法
2019/01/22 Python
Python中extend和append的区别讲解
2019/01/24 Python
Python删除n行后的其他行方法
2019/01/28 Python
使用Python3+PyQT5+Pyserial 实现简单的串口工具方法
2019/02/13 Python
Python模块、包(Package)概念与用法分析
2019/05/31 Python
在django中实现页面倒数几秒后自动跳转的例子
2019/08/16 Python
python爬虫 批量下载zabbix文档代码实例
2019/08/21 Python
查看keras各种网络结构各层的名字方式
2020/06/11 Python
浅谈CSS3中display属性的Flex布局的方法
2017/08/14 HTML / CSS
俄罗斯运动、健康和美容产品在线商店:Lactomin.ru
2020/07/23 全球购物
百度JavaScript笔试题
2015/01/15 面试题
最新的互联网创业计划书
2014/01/10 职场文书
银行员工辞职信范文
2014/01/20 职场文书
2014年入党积极分子党课学习心得体会模板
2014/04/03 职场文书
商场周年庆活动方案
2014/08/19 职场文书
慰问信格式
2015/02/14 职场文书
比较node.js和Deno
2021/04/27 Javascript
Win11怎么添加用户?Win11添加用户账户的方法
2022/07/15 数码科技