zoukankan      html  css  js  c++  java
  • tab切换

    说明:

      

    html 部分:

      <div>
          <ul class="tab-nav-box tp-tab tp-tab01" data-content=".tab-content-box-3">
              <a class="tab-item active" href="javascript:void(0)">tab1</a>
              <a class="tab-item" href="javascript:void(0)">tab2</a>
              <a class="tab-item" href="javascript:void(0)">tab3</a>
          </ul>
            <div class="tab-box tab-content-box-1">
              <div class="content-item active">content tab1</div>
              <div class="content-item">content tab2</div>
              <div class="content-item">content tab3</div>
            </div>
        </div>

    js 部分/*

     * @name        tab.js tab切换功能
    
     */
     define(function(require, exports, module) {
         // 通过 require 引入依赖
         // var bind = require('../common/bind.js');
        //找到页面上data-role =tab元素
        var Tab = function(ele,config){
            this.cfg = $.extend({
               trigger:'touchend',
               index:0, // 默认选中的索引项
               content: '.tab-content-box'
            }, config);
            this.init(ele);
        };
        Tab.prototype = {
            constructor:Tab,
            init: function(ele){
              var self = this;
              this.$ele = ele;
    
              this.$content = $(self.$ele.data("content") || self.cfg.content);
              this.renderTab();
              this.event();
            },
            renderTab:function(){
              var self = this;
              this.$ele.children().eq(self.cfg.index).addClass('active');
              this.$content.children().eq(self.cfg.index).addClass('active');
            },
            event:function(){
              var self = this;
              self.$ele.on(self.cfg.trigger, '.tab-item', function(){
    
                var _this = $(this);
                if(_this.hasClass('active')) return;
                _this.addClass('active').siblings().removeClass('active');
                self.$content.children().removeClass('active').eq(_this.index()).addClass('active');
              })
            }
        }
        $.extend($.fn,{
            tab:function(config){
                return new Tab($(this), config || {});
            }
        });
        module.exports = $;
     })
  • 相关阅读:
    python如何打开一个大文件?
    python中的多进程与多线程(二)
    python中的多进程与多线程(一)
    python中的深拷贝与浅拷贝
    2018 pycharm最近激活码
    python中的新式类与旧式类
    用python优雅打开文件及上下文管理协议
    解决Mac上安装mysqlclient的错误
    用python实现一个简单的服务器
    高阶函数
  • 原文地址:https://www.cnblogs.com/restart77/p/12336977.html
Copyright © 2011-2022 走看看