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动态追加页面数据以及事件委托详解
May 06 jQuery
JQuery实现图片轮播效果
May 08 jQuery
jQuery 中msgTips 顶部弹窗效果实现代码
Aug 14 jQuery
jquery+css实现下拉列表功能
Sep 03 jQuery
jQuery选择器之表单元素选择器详解
Sep 19 jQuery
jQuery实现html双向绑定功能示例
Oct 09 jQuery
jQuery实现鼠标移到某个对象时弹出显示层功能
Aug 23 jQuery
详解jQuery设置内容和属性
Apr 11 jQuery
jQuery zTree树插件的使用教程
Aug 16 jQuery
jquery中attr、prop、data区别与用法分析
Sep 25 jQuery
jQuery/JS监听input输入框值变化实例
Oct 17 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 google或baidu分页代码
2009/11/26 PHP
php access 数据连接与读取保存编辑数据的实现代码
2010/05/12 PHP
使用Discuz关键词服务器实现PHP中文分词
2014/03/11 PHP
php判断访问IP的方法
2015/06/19 PHP
php获取远程文件内容的函数
2015/11/02 PHP
Laravel 5使用Laravel Excel实现Excel/CSV文件导入导出的功能详解
2017/10/11 PHP
基于JQuery的访问WebService的代码(可访问Java[Xfire])
2010/11/19 Javascript
javascript scrollTop正解使用方法
2013/11/14 Javascript
javascript委托(Delegate)blur和focus用法实例分析
2015/05/26 Javascript
Webpack 实现 Node.js 代码热替换
2015/10/22 Javascript
js canvas实现擦除动画
2016/07/16 Javascript
vue.js vue-router如何实现无效路由(404)的友好提示
2017/12/20 Javascript
JS中touchstart事件与click事件冲突的解决方法
2018/03/12 Javascript
函数式编程入门实践(一)
2019/04/20 Javascript
js实现简单五子棋游戏
2020/05/28 Javascript
Javascript实现鼠标移入方向感知
2020/06/24 Javascript
Python中turtle作图示例
2017/11/15 Python
python数据分析数据标准化及离散化详解
2018/02/26 Python
Python求两点之间的直线距离(2种实现方法)
2019/07/07 Python
python基于socket实现的UDP及TCP通讯功能示例
2019/11/01 Python
Python爬虫爬取糗事百科段子实例分享
2020/07/31 Python
python 多线程共享全局变量的优劣
2020/09/24 Python
在vscode中启动conda虚拟环境的思路详解
2020/12/25 Python
Python实现王者荣耀自动刷金币的完整步骤
2021/01/22 Python
html5实现滑块功能之type="range"属性
2020/02/18 HTML / CSS
施华洛世奇加拿大官网:SWAROVSKI加拿大
2018/06/03 全球购物
编写用C语言实现的求n阶阶乘问题的递归算法
2014/10/21 面试题
New delete 与malloc free 的联系与区别
2013/02/04 面试题
成绩单家长评语大全
2014/04/16 职场文书
2014个人年度工作总结
2014/12/15 职场文书
五一劳动节活动总结
2015/02/09 职场文书
2016企业先进集体事迹材料
2016/02/25 职场文书
python基础之爬虫入门
2021/05/10 Python
mysql 索引合并的使用
2021/08/30 MySQL
Java对文件的读写操作方法
2022/04/29 Java/Android
MySQL事务的ACID特性以及并发问题方案
2022/07/15 MySQL