首页 > 代码库 > 仿淘宝订单列表下标指针
仿淘宝订单列表下标指针
上图的功能,代码直接复制可用:
<!doctype html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script><style>/*导航*/*{margin:0;padding:0}a{text-decoration:none}.box{margin:10px}.order-class{width:800px;font-size:0}.order-class .bar{font-size:14px;font-weight:700;width:100px;text-align:center;display:inline-block;color:#333;padding:0 10px;height:20px;border-left:1px solid #ccc;border-right:1px solid #ccc;margin:0 0 0 -1px}.order-class .on{color:#f6615b;font-size:14px;font-weight:bold}/*指针*/.order-class-pointer{width:800px;height:3px;background:#c8c8c8;margin:10px 0 0 -1px}.order-class-pointer .pointer{width:121px;height:3px;background:#f6615b}</style></head><body><div class="box"> <div class="order-class"> <a href="http://www.mamicode.com/#" class="bar on"> <span>所有订单</span> </a> <a href="http://www.mamicode.com/#" class="bar"> <span>待付款</span> <span class="pinkColor">0</span> </a> <a href="http://www.mamicode.com/#" class="bar"> <span>待发货</span> <span class="pinkColor">0</span> </a> <a href="http://www.mamicode.com/#" class="bar"> <span>待收货</span> <span class="pinkColor">3</span> </a> <a href="http://www.mamicode.com/#" class="bar"> <span>待评价</span> <span class="pinkColor">2</span> </a> </div> <!--指针--> <div class="order-class-pointer"> <div class="pointer" id="pointer"></div> </div></div><script language="javascript" type="text/javascript">pointer(‘order-class‘,121);function pointer(nav,classWid){ var orderClass = $(‘.‘+nav).children(‘a‘),//导航dom wid = classWid,//下标宽,也就是一条分类的宽 timeout,//定时器 Sub;//下标 //找到on确定下标位置 $(orderClass).each(function(){ if($(this).hasClass(‘on‘)) Sub = $(this).index(‘.bar‘); }); setPointer(Sub*wid);//初始化 //设置下标位置 function setPointer(px){ $(‘#pointer‘).css(‘margin-left‘,px + ‘px‘); } //获取下标位置 function getPointer(){ return parseInt($(‘#pointer‘).css(‘margin-left‘)); } //指针滑动,分十次移动 function subSlide(allDis){ var distan = (allDis - getPointer())/10; var i=0; function scro(){ i<9 ? setPointer(getPointer()+distan) : setPointer(allDis); if(i==9) return; i++; timeout = setTimeout(scro,50); } timeout = setTimeout(scro,50); } //绑定事件 orderClass.on({ ‘mouseover‘:function(){ clearTimeout(timeout); var allDis = wid*orderClass.index(this); subSlide(allDis); }, ‘mouseout‘:function(){ clearTimeout(timeout); var allDis = Sub*wid; subSlide(allDis); } });}</script></body></html>
仿淘宝订单列表下标指针
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。