登录  /  注册
首页 > web前端 > js教程 > 正文

jQuery Collapse1.1.0折叠插件使用方法介绍

小云云
发布: 2017-12-29 13:22:52
原创
2217人浏览过

本文主要介绍了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);
登录后复制

相关推荐:

css属性border-collapse与border-spacing的区别详解

CSS 表格中的单元格边框重叠的border-collapse属性

css border-collapse的使用详解

以上就是jQuery Collapse1.1.0折叠插件使用方法介绍的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号