效果如上,左右箭头点击,相应左右滑动一个功能菜单的长度,点击BTN2时若所有功能菜单没溢出就不显示箭头不允许左右滑动。

可根据初始化功能菜单的个数,判断。若某个tabCon没有内容,则删除相应tabCon和tabBtn。

HTML:

<div class="tabBtn">
<div class="btn1 Tbtn" id="OnTBtn">btn1</div>
<div class="btn2 Tbtn">btn2</div>
<div class="btn3 Tbtn">btn3</div>
<div class="btn4 Tbtn">btn4</div>
<div class="btn5 Tbtn">btn5</div>

</div>

<div class="tabCon">

<div class="tab1 tab" id="OnTCon">
<i class="leftArrow"></i>
<div>

<ul>

<li class="fun-menu">
<i></i>
<span>功能菜单1</span>
</li>
<li class="fun-menu">
<i></i>
<span>功能菜单2</span>
</li>
<li class="fun-menu">
<i></i>
<span>功能菜单3</span>
</li>

</ul>

</div>
<i class="rightArrow"></i>
</div>

.....类推5个。

CSS:

.tabBtn{
/* width: 300px;
height: 42px;
display: inline-block;
position: absolute;
right: 40px;
bottom: 15px;*/
width: 360px;
height: 32px;
display: inline-block;
position: absolute;
right: 40px;
bottom: 0;
}
.tabBtn div{
/*width: 58px;
height: 40px;*/
width: 70px;
height: 32px;
background: #E28920;
float: left;
border: 1px solid #8D8D8D;
border-top-left-radius: 20px;
border-top-right-radius: 20px;
text-align: center;
/* line-height: 42px;*/
line-height: 32px;
}
#OnTBtn{
background: #E2573E;
}
/*tap内容*/
.tabCon{
width: 100%;
height: 50px;
background:#d8cbcb;
/*position: relative;*/
}
.tab{
width: 100%;
height: 50px;
float: left;
text-align: left;
line-height: 50px;
position: absolute;
display: none;
box-sizing: border-box;

}
#OnTCon{
display: block;
}
.tab>div{
height: 50px;
overflow: hidden;
margin: 0 30px;
position: relative;
}
.tab ul{
position: absolute;
}
.fun-menu{
width: 104px;
height: 34px;
background: #F4F5F9;
float: left;
margin: 7px 6px 7px 0;
line-height: 34px;
box-sizing: border-box;
display: inline-block;

}
.fun-menu i{
width: 28px;
height: 28px;
display: inline-block;
margin-right: 3px;
margin-left: 6px;
margin-top: 3px;
float: left;
background: #8A2BE2;

}
.fun-menu span{
width: 65px;
height: 34px;
line-height: 34px;
display: inline-block;
float: left;
}
.leftArrow,.rightArrow{
width: 30px;
height: 30px;
display: inline-block;
position: absolute;


}
.leftArrow{
background: url(../img/leftArrow.png) no-repeat;
background-size: 100% 100%;
top: 7px;
display: none;
}
.rightArrow{
right: 0;
top: 10px;
background: url(../img/rightArrow.png) no-repeat;
background-size: 100% 100%;
display: none;
}

JS:

$(document).ready(function() {
var click_num =[0,0,0,0,0,0];
var curIndex=0;
var li_size=0;
var w_width = $(window).width();
var screenSize = Math.floor((w_width - 60) / 110);
$(".Tbtn").each(function(index) {
var Tbtn = $(this);
$(this).click(function() {

$("#OnTCon").removeAttr("id");
$("#OnTBtn").removeAttr("id");

$(".tab").eq(index).attr("id", "OnTCon");
Tbtn.attr("id", "OnTBtn");
curIndex=index;
tbnOnclick();
});

});
tbnOnclick();
function tbnOnclick(){
li_size = $("#OnTCon ul li").size();
$("#OnTCon ul").width(li_size * 110);

if(li_size - screenSize>0){
$(".leftArrow").css("display","block");
$(".rightArrow").css("display","block");
// $(".leftArrow").css("background","url(image/top/left-A.png) no-repeat");
// $(".rightArrow").css("background","url(image/top/right-A.png) no-repeat");
}else{
/* $(".leftArrow").css("background","url(image/top/left-B.png) no-repeat");
$(".rightArrow").css("background","url(image/top/right-B.png) no-repeat");*/
$(".leftArrow").css("display","none");
$(".rightArrow").css("display","none");
}
}

var lCanClick=true;
var rCanClick=true;
$(".rightArrow").click(function() {
if(rCanClick==false) return;
console.log(click_num[curIndex]);
if(click_num[curIndex] < li_size - screenSize) {
click_num[curIndex]++;
rCanClick=false;
$("#OnTCon ul").animate({
left: -click_num[curIndex] * 110
}, 500,function(){
rCanClick=true;
});
}else{
click_num[curIndex]=li_size - screenSize;

}
});

$(".leftArrow").click(function() {
if(lCanClick==false) return;
console.log(click_num[curIndex]);
var leftPosition = $("#OnTCon ul").css("left");
leftPosition = leftPosition.replace("px", "");
if(parseInt(leftPosition) < 0) {
click_num[curIndex]--;
lCanClick=false;
$("#OnTCon ul").animate({
left: -click_num[curIndex] * 110
}, 500,function(){
lCanClick=true;
});
}else{
click_num[curIndex]=0;
}
});

})

初始化确定TAB个数:

最新文章

  1. bzoj 1588 splay模板题
  2. python实现简易数据库之三——join多表连接和group by分组
  3. NSCharacterSet 简单用法
  4. SQL把表中的数据复制到另一个数据库中
  5. MySQL 触发器简单实例
  6. emWin(ucGui)的Edit控件退格处理方法 worldsing
  7. 设计模式17---设计模式之模板方法模式(Template Method)(行为型)
  8. Oracle 如何让别人能够连接到你的数据库
  9. CSS样式做圆角
  10. bzoj2243[SDOI2011]染色 树链剖分+线段树
  11. URL重定向漏洞,python打造URL重定向漏洞检测脚本
  12. 微信h5支付
  13. $.extend()浅拷贝深拷贝
  14. event 事件2
  15. ABBYY FineReader Pro for Mac有哪些特性(上)
  16. cisco 交换机通过console 导入 IOS
  17. delphi checklistbox用法
  18. 全新升级的WiFi无线上网短信认证系统,适用于咖啡厅、足浴等公共场所,提高门门店营业收入
  19. Vue slot简单理解
  20. lua中实现倒计时

热门文章

  1. IE8 jquery解析xml的兼容问题
  2. GCD一些常用的方法
  3. tomcat7+jdk1.8一键安装脚本
  4. Latex环境安装
  5. HDU 1525 Euclid&#39;s Game 博弈
  6. PHP interface(接口)的示例代码
  7. Github的命令清除
  8. linux 下 apache相关;启动、停止、重启命令;配置文件位置等等
  9. 微信小程序-设备
  10. RabbitMQ 基础概念