<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <meta name="format-detection" content="email=no" /> <meta name="keywords" content="xxx" /> <meta name="description" content="xxx" /> <title>xxx</title> <style> /* * 2016-10-14 */ /*全局*/ html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video{margin:0;padding:0;border:0;font-size:100%;font:inherit;vertical-align:baseline;outline:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;color:#000;-webkit-tap-highlight-color:rgba(0,0,0,0);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;} body{line-height:1;font-family:Microsoft YaHei,Helvetica,Tahoma,Arial,5FAE8F6F96C59ED1,sans-serif} article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block} ol,ul{list-style:none} blockquote,q{quotes:none} blockquote:before,blockquote:after,q:before,q:after{content:'';content:none} strong{font-weight:bold} table{border-collapse:collapse;border-spacing:0} img{border:0} a{display:block;text-decoration:none} body{background:#fff;position: relative;} html,body{100%;overflow-x:hidden;} @media only screen and (max-640px){html,body{font-size:25px}} @media only screen and (max-540px){html,body{font-size:22.5px}} @media only screen and (max-480px){html,body{font-size:18.5px}} @media only screen and (max-400px){html,body{font-size:16.5px}} @media only screen and (max-360px){html,body{font-size:15px}} @media only screen and (max-320px){html,body{font-size:14px}} @media only screen and (max-240px){html,body{font-size:13.5px}} /*公共*/ .hide{display:none} .c8420{color: #ff8420;} /*私有*/ /*頂部tab*/ .tab_box{text-align: center;background: #fff;border-bottom: 1px solid #ebebeb;height: 50px;padding-left: 15px;box-sizing: border-box;} .tab_box ul{ 1000px;} .tab_box ul li{color: #333;font-size: 16px;position: relative;float: left;text-align: center;height: 50px;110px;line-height: 50px;} .tab_box .under{position: absolute;border-bottom: 2px solid #ff8420; 80px;bottom: 0;left: 50%;margin-left: -40px;} .tab_box .last{margin-right: 0;} .tab_box .on{color: #ff8420;} /*内容*/ .container{} </style> </head> <body> <!-- tab start --> <div class="tab_box" id="tab_box"> <ul> <li data_name="aaaa">aaaa<span class="under"></span></li> <li data_name="bbbb">bbbb<span class="under hide"></span></li> <li data_name="cccc">cccc<span class="under hide"></span></li> <li data_name="dddd">dddd<span class="under hide"></span></li> <li data_name="eeee">eeee<span class="under hide"></span></li> <li data_name="ffff" class="last">ffff<span class="under hide"></span></li> </ul> </div> <!-- tab end --> <script src="http://valar.huainanhai.com/common/lib/zepto.1.1.3.js" type="text/javascript"></script> <script src="http://valar.huainanhai.com/common/lib/iscroll.5.0.js"></script> <script> // 2016/10/17 var data_name = _get('data_name')?_get('data_name'):''; var myscroll = null; _init(); //初始化 function _init(){ //修改nav的宽度 setTabUlWidth(); //加载iscoll tab_box_load(); //首次加载 if(data_name){ var obj = $('#tab_box ul li[data_name="'+data_name+'"]'); if(obj.length){ changeTab(obj); //让tab滚动到指定tab //将一个jQuery对象转换成DOM对象:[index]和.get(index); var offset_left = obj[0].offsetLeft; myscroll.scrollTo(-offset_left+110,0); }else{ changeTab($('#tab_box ul li').eq(0)); } }else{ changeTab($('#tab_box ul li').eq(0)); } } // 设置tab ul的宽度 function setTabUlWidth(){ var tab_li_width = $('#tab_box li').width(); var tab_li_num = $('#tab_box li').length; $('#tab_box ul').css('width',tab_li_num*tab_li_width+50); } //tab点击监听 $('#tab_box ul li').on('click',function(){ changeTab($(this)); }); //切换tab function changeTab(obj){ $('#tab_box ul li').removeClass('on'); $('#tab_box ul li span').hide(); obj.addClass('on'); obj.children('.under').show(); data_name = obj.attr('data_name'); } //加载iscoll function tab_box_load(){ myscroll = new iScroll("tab_box",{ snap: false, momentum: true, vScroll: false, hScroll: true, hScrollbar: false, }); } // 获取get参数 function _get(name){ //正则解释 // ()表示一个子表达式 1.在被修饰匹配次数的时候,括号中的表达式可以作为整体被修饰2.取匹配结果的时候,括号中的表达式匹配到的内容可以被单独得到 // (^|&) 匹配字符串开头或者&字符 // ([^&]*) 匹配除了&之外的字符0次或多次 相当于 {0,} // (&|$) 匹配字符串结尾或者&字符 // match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。 var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var data = window.location.search.substr(1).match(reg); return data!=null?decodeURIComponent(data[2]):null; } </script> </body> </html>