zoukankan      html  css  js  c++  java
  • 简单的封装tab选项卡

    //tab
    //参数1:整体选项卡
    //参数2:交互的btn
    //参数3:要展现的内容
    //参数4:交互的btn当前状态
    //参数5:事件类型
    function tabs(obj, nav, cont, cur, type){
        var c = cont;
        var obj = $(obj),
            nav = $(nav,obj),
            cont = $(cont,obj);
    
        nav.first().addClass(cur);
        cont.first().show();
    
        nav.each(function(index) {
            $(this).bind(type,function(){
                nav.removeClass(cur);
                $(this).addClass(cur);
                cont.hide();
                cont.eq(index).show();
            });
        });
    }
    tabs(".tab", ".tab-nav li", ".tab-item", "on", "click");
    

    html 代码

    <!doctype html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>Document</title>
    	<style>
    .tab-item{
    	 100px;
    	height: 100px;
    	background: #000;
    	display: none;
    	color: #fff
    
    }
    .tab-nav{
    
    }
    .tab-nav li{
    	float: left;
    	 20px;
    	margin:10px;
    	height: 20px;
    	background: #ccc;
    	list-style: none;
    }
    .tab-nav li.on{
    	background: red;
    }
    
    	</style>
    </head>
    <body>
    	<div class="tab">
    		<div class="tab-item">1</div>
    		<div class="tab-item">2</div>
    		<div class="tab-item">3</div>
            <ol class="tab-nav">
            	<li>1</li>
            	<li>2</li>
            	<li>3</li>
            </ol>
    	</div>
    </body>
    </html>
    

      

     很简单的选项卡效果,以后可以继续优化 

  • 相关阅读:
    pycharm使用技巧
    for 循环
    面向对象进阶
    python实现socket上传下载文件-进度条显示
    python实现进度条--主要用在上传下载文件
    django下常用查询的API
    django下model.py模型的定义
    django下数据库配置
    ORM机制简介
    views.py文件详解
  • 原文地址:https://www.cnblogs.com/yangjingjing/p/5333873.html
Copyright © 2011-2022 走看看