jQuery Collapse1.1.0折叠插件简单使用


Posted in jQuery onAugust 28, 2017

本文实例为大家分享了jQuery Collapse1.1.0折叠插件的使用,供大家参考,具体内容如下

/*!
* jQuery collapse - A Wizard Plugin - http://www.cnblogs.com/yeyuansheng/
* ------------------------------------------------------------------------------------
*
* @version 1.1.0
* @since 2017.08.28
* @author 夜原生
* @documentation http://www.cnblogs.com/yeyuansheng/
*
* Usage with default values:
* ------------------------------------------------------------------------------------
* {
* panel: '',//默认空为第一个标签
* content: '',//默认空为第二个标签
* active: 'active',//点击样式
* shut: true,//展开的在次点击可闭合
* style: 'y',//x,y,0上下左右滑动展开/无动作展开
* speed: 200,//动作的速度
* event: "click",//动作
* class: 'active',//item 样式
* func: function(){},//增加事件
* open:''//默认打开
* }
*/

(function($) {
  var collapse = {
    version:'1.1.0',
    style:{
      slideRight: {
        width : "hide", 
        paddingLeft : "hide", 
        paddingRight : "hide", 
        marginLeft : "hide", 
        marginRight : "hide" 
      },
      slideLeft: {
        width : "show",
        paddingLeft : "show",
        paddingRight : "show",
        marginLeft : "show",
        marginRight : "show"
      },
      slideUp: {
        borderTopWidth: "hide",
        borderBottomWidth: "hide",
        paddingTop: "hide",
        paddingBottom: "hide",
        height: "hide"
      },
      slideDown: {
        borderTopWidth: "show",
        borderBottomWidth: "show",
        paddingTop: "show",
        paddingBottom: "show",
        height: "show"
      }
    },
    init:function(options){
      var opts = $.extend({}, $.fn.collapse.defaults, options);
      if(opts.style == 'x' && options.shut == 'undefined'){
        opts.shut = false;
      }
      return opts;
    },
    clickChange:function(obj,op){
      var panel = (op.panel == '')?$(obj).children(':first'):$(obj).find('> '+op.panel);
      panel.on(op.event,function(){ 
        var parent = $(this).parent();
        var sub = (op.content == '')?parent.children().eq(1):parent.find('> '+op.content);
        if($(sub).is(':visible')) {
          if(op.shut){
            collapse._animate(sub,op,0,function(){
              parent.removeClass(op.class);
              op.func();
            });
          }
        }else{
          parent.siblings().each(function(){
            var t = $(this);
            if(t.hasClass(op.active)){
              var uls = (op.content == '')?t.children().eq(1):t.find('> '+op.content);
              if(uls.length == 0){
                t.removeClass(op.active);
              }else{
                collapse._animate(uls,op,0,function(){
                  t.removeClass(op.active);
                });
              } 
            }
          });
          parent.addClass(op.active);
          collapse._animate(sub,op,1,function(){
            op.func();
          });
        }
      });
    },
    itemChange:function(item,op){
      var uls = (op.content == '')?$(item).children().eq(1):$(item).children().find('> '+op.content);
      uls.children().on(op.event,function(){
        $(item).parent().children().each(function(){
          if(op.content == ''){
            $(this).children().eq(1).children().removeClass(op.class);
          }else{
            $(this).children().find('> '+op.content).children().removeClass(op.class);
          }
        });
        $(this).addClass(op.class);
      });
    },
    _animate:function(obj,op,bool,callback){
      if(op.style){
        if(bool){
          slide =(op.style == 'x')?collapse.style.slideLeft:collapse.style.slideDown;
        }else{
          slide =(op.style == 'x')?collapse.style.slideRight:collapse.style.slideUp;
        } 
        obj.animate(slide,op.speed,callback); 
      }else{
        (bool)?obj.show():obj.hide();//可以改用CLASS控制
      }
    },
    open:function(obj,op,open){
      var li = $(obj).children().eq(open[0]);
      li.addClass(op.active);
      var ul = (op.content == '')?li.children().eq(1):li.find('> '+op.content);
      ul.show();
      ul.children().eq(open[1]).addClass(op.class);
    }
  }
  $.fn.collapse = function(options){
    var opts = collapse.init(options);
    if(opts.open != '')collapse.open(this,opts,opts.open);
    $(this).children().each(function(){
      collapse.clickChange(this,opts);
      collapse.itemChange(this,opts);
    }); 
  }
  $.fn.collapse.defaults = { 
    panel: '',
    content: '',
    active: 'active',
    shut: true,
    style: 'y',
    speed: 200,
    event: "click",
    class: 'active',
    func: function(){},
    open:''
  }
})(jQuery);

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

jQuery 相关文章推荐
jQuery插件FusionCharts绘制的2D帕累托图效果示例【附demo源码】
Mar 28 jQuery
jquery中关于bind()方法的使用技巧分享
Mar 30 jQuery
使用jQuery,Angular实现登录界面验证码详解
Apr 27 jQuery
jQuery手风琴的简单制作
May 12 jQuery
浅谈struts1 & jquery form 文件异步上传
May 25 jQuery
基于jQuery封装的分页组件
Jun 26 jQuery
jQuery操作DOM_动力节点Java学院整理
Jul 04 jQuery
使用vue与jquery实时监听用户输入状态的操作代码
Sep 19 jQuery
jQuery实现打开网页自动弹出遮罩层或点击弹出遮罩层功能示例
Oct 19 jQuery
jQuery实现标签子元素的添加和赋值方法
Feb 24 jQuery
jQuery表单选择器用法详解
Aug 22 jQuery
jQuery实现简单评论功能
Aug 19 jQuery
解决IE7中使用jQuery动态操作name问题
Aug 28 #jQuery
jQuery菜单实例(全选,反选,取消)
Aug 28 #jQuery
基于jQuery实现图片推拉门动画效果的两种方法
Aug 26 #jQuery
详解webpack3如何正确引用并使用jQuery库
Aug 26 #jQuery
jQuery图片缩放插件smartZoom使用实例详解
Aug 25 #jQuery
使用jQuery实现页面定时弹出广告效果
Aug 24 #jQuery
使用jquery+iframe做一个ajax上传效果(实例)
Aug 24 #jQuery
You might like
用PHP程序实现支持页面后退的两种方法
2008/06/30 PHP
php设计模式之命令模式使用示例
2014/03/02 PHP
PHP安全的URL字符串base64编码和解码
2014/06/19 PHP
php使用Cookie控制访问授权的方法
2015/01/21 PHP
Ubuntu中搭建Nginx、PHP环境最简单的方法
2015/03/05 PHP
讲解WordPress中用于获取评论模板和搜索表单的PHP函数
2015/12/28 PHP
Zend Framework校验器Zend_Validate用法详解
2016/12/09 PHP
javascript 操作select下拉列表框的一点小经验
2010/03/20 Javascript
JQuery 选项卡效果(JS与HTML的分离)
2010/04/01 Javascript
浅析JavaScript中的类型和对象
2013/11/29 Javascript
深入理解javascript中return的作用
2013/12/30 Javascript
Node.js 服务器端应用开发框架 -- Hapi.js
2014/07/29 Javascript
jQuery中replaceWith()方法用法实例
2014/12/25 Javascript
jQuery实现带渐显效果的人物多级关系图代码
2015/10/16 Javascript
简单实现轮播图效果的实例
2016/07/15 Javascript
js字符串与Unicode编码互相转换
2017/05/17 Javascript
jQuery实现监听下拉框选中内容发生改变操作示例
2018/07/13 jQuery
详解Vue取消eslint语法限制
2018/08/04 Javascript
js继承的这6种方式!(上)
2019/04/23 Javascript
基于layui的table插件进行复选框联动功能的实现方法
2019/09/19 Javascript
浅析vue cli3 封装Svgicon组件正确姿势(推荐)
2020/04/27 Javascript
vue 数据双向绑定的实现方法
2021/03/04 Vue.js
python使用原始套接字发送二层包(链路层帧)的方法
2019/07/22 Python
django使用JWT保存用户登录信息
2020/04/22 Python
HTML如何让IMG自动适应DIV容器大小的实现方法
2020/02/25 HTML / CSS
HTML5中外部浏览器唤起微信分享功能的代码
2020/09/15 HTML / CSS
米兰网婚纱礼服法国网上商店:Milanoo法国
2016/08/20 全球购物
英国床垫在线:Mattress Online
2016/12/07 全球购物
英国领先的名牌服装折扣零售商:Brown Bag Clothing
2019/01/08 全球购物
Hello Molly美国:女性时尚在线
2019/08/26 全球购物
英语专业毕业生自我鉴定
2013/11/09 职场文书
骨干教师培训方案
2014/05/06 职场文书
车间统计员岗位职责
2015/04/14 职场文书
python opencv通过4坐标剪裁图片
2021/06/05 Python
Python Pandas 删除列操作
2022/03/16 Python
《堡垒之夜》联动《刺客信条》 4月7日正式上线
2022/04/06 其他游戏