html 切换状态分栏
2016-08-13 15:50
302 查看
一个自己的分栏工具,可以快速创建分栏效果。
HTML:
css:
js:
调用方式:
效果图:
完整例子:
HTML:
<div class="g-header"> <!-- 导航栏 --> <div class="g-nav"> <div class="g-wrap"> <ul class="g-nav-list"> <li ><span id="doing">分栏一</span></li> <li class="selected"><span id="end">分栏二</span></li> </ul> </div> </div> </div>
css:
.g-header{ background-color:#fff; position:relative; z-index:3; _zoom:1; } .g-nav { height: 39px; border-bottom: 1px solid #d5d5d5; box-shadow: 0 1px 3px 0px rgba(160,160,160,0.2); } .g-nav-list { width: 100%; display: box; display: -webkit-box; display: -moz-box; } .g-nav-list li { position: relative; text-align: center; box-flex: 1; -webkit-box-flex: 1; -moz-box-flex: 1; } .g-nav-list span { display: inline-block; margin: 0 auto; width: 100%; line-height: 37px; text-align: center; color: #666666; } .g-nav-list .selected{ border-bottom: 2px solid #db3652 } .g-nav-list .selected span { width: 100%; color: #db3652; line-height: 38px; }
js:
$.fn.toolBar = function changeBar(firstAction,sectionAction){ <!--firstAction事件--> $("#doing").click(function(){ var index = $(".g-nav-list").find("li[class=selected]").index(); if(index == 0)return; changeBtnState(); if(firstAction){ firstAction(); } }); <!--sectionAction事件--> $("#end").click(function(){ var index = $(".g-nav-list").find("li[class=selected]").index(); if(index == 1)return; changeBtnState(); if(sectionAction){ sectionAction(); } }); } <!--切换按钮状态--> function changeBtnState(){ $(".g-nav-list li").each(function(index){ if($(this).attr("class")=="selected"){ $(this).attr("class","none"); }else{ $(this).attr("class","selected"); } }); }
调用方式:
$().toolBar( function action_doing(){ //分栏一事件 }, function action_end(){ //分栏二事件 } );
效果图:
完整例子:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, width=device-width">
<style type="text/css">
*{
margin: 0;
padding: 0;
}
ul >li{
list-style-type: none;
}
.g-header{ background-color:#fff; position:relative; z-index:3; _zoom:1; } .g-nav { height: 39px; border-bottom: 1px solid #d5d5d5; box-shadow: 0 1px 3px 0px rgba(160,160,160,0.2); } .g-nav-list { width: 100%; display: box; display: -webkit-box; display: -moz-box; } .g-nav-list li { position: relative; text-align: center; box-flex: 1; -webkit-box-flex: 1; -moz-box-flex: 1; } .g-nav-list span { display: inline-block; margin: 0 auto; width: 100%; line-height: 37px; text-align: center; color: #666666; } .g-nav-list .selected{ border-bottom: 2px solid #db3652 } .g-nav-list .selected span { width: 100%; color: #db3652; line-height: 38px; }
</style>
</head>
<body>
<div class="g-header"> <!-- 导航栏 --> <div class="g-nav"> <div class="g-wrap"> <ul class="g-nav-list"> <li ><span id="doing">分栏一</span></li> <li class="selected"><span id="end">分栏二</span></li> </ul> </div> </div> </div>
<script src="jquery.min.js"></script>
<script src="js.js"></script>
<script>
$().toolBar(
function action_doing(){
//分栏一事件
alert("分栏一事件");
},
function action_end(){
//分栏二事件
alert("分栏二事件");
}
);
</script>
</body>
</html>
相关文章推荐
- ASP常用的几个功能模块封装成函数调用(登录验证,状态切换。。) http://www.tsingfeng.com/archives/?article-89.html
- html li css选中状态切换
- html li css选中状态切换
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- android 的数据状态保存,横竖屏切换时的操作
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- 技巧:如何禁止输入法切换到全角状态
- android背景图片及状态切换
- [android] Activity 的生命周期 以及 横屏竖屏切换时 Activity 的状态变化
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- web前端,标签切换总结5load()加载新的html界面
- 线程实现/状态切换/常用API分析
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解
- Unity4.5动画控制状态切换监听脚本
- ImageView切换两种状态下的模式
- iOS应用程序生命周期(前后台切换,应用的各种状态)详解 mark
- HTML5+CSS3构建同页面表单间的动画切换
- Fragment切换的时候,保存数据状态(执行onResume),不重新加载
- checkbox点击切换选中状态
- Android中配置改变(Configuration)的处理状态(重点横竖屏切换)