tab选项卡 想实现一个浮动的tab选项卡效果,有没有好的思路或者例子。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 简单写了个给LZ作为参考<style type="text/css">.selected{ background-color: red;}span{ cursor: pointer;}</style><script type="text/javascript">function selected(obj){ for(var i = 1 ; i < 3 ; ++i){ document.getElementById('item' + i + 'content').style.display = 'none'; document.getElementById('item' + i).className = ''; } obj.className = 'selected'; document.getElementById(obj.id + 'content').style.display = 'block';}</script><body> <div> <div> <span class="selected" id="item1" onclick="selected(this)">选项卡一</span> <span id="item2" onclick="selected(this)">选项卡二</span> </div> <div> <div id="item1content">选项卡一的内容</div> <div style="display:none;" id="item2content">选项卡二的内容</div> </div> </div></body> 什么叫 浮动的tab选项卡?参考:http://www.cnblogs.com/yjzhu/archive/2012/12/28/2837593.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><style type="text/css">li{ float:left;}</style><script type="text/javascript">(function(){ if(window['z']){ alert("the namespace z has been used,change anthor please"); return; }else{ window['z']={}; } function addTab(){ var div=document.createElement("div"); var ul=document.createElement("ul"); ul.style.marginLeft="-40px"; var show=document.createElement("div"); for(var i=0;i<arguments.length;i++){ var li=document.createElement("li"); li.style.width="100px"; li.style.textAlign="center"; li.style.listStyleType="none"; li.innerHTML=arguments[i]; li.style.backgroundColor="blue"; li.style.borderStyle="solid"; li.style.borderWidth="1px"; li.onmouseover=function(){ this.style.backgroundColor="green"; this.style.borderBottomColor='green'; show.innerHTML=this.innerHTML; } li.onmouseout=function(){ this.style.backgroundColor="blue"; this.style.borderBottomColor='black'; } ul.appendChild(li); } show.style.width=arguments.length*102+"px"; show.style.height=arguments.length*100+"px"; show.style.clear="both"; show.style.backgroundColor="green"; div.appendChild(ul); div.appendChild(show); document.body.appendChild(div); } window['z']['addTab']=addTab;})();window.onload=function(){ z.addTab("1","2",'test');}</script></head><body></body></html>?? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>tab页切换</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript"> function switchTab(ProTag, ProBox) { for (i = 1; i < 5; i++) { if ("tab" + i == ProTag) { document.getElementById(ProTag).getElementsByTagName("a")[0].className = "on"; } else { document.getElementById("tab" + i).getElementsByTagName("a")[0].className = ""; } if ("con" + i == ProBox) { document.getElementById(ProBox).style.display = ""; } else { document.getElementById("con" + i).style.display = "none"; } } } </script> <style type="text/css"> * { padding: 0; margin: 0; line-height: 25px; font-size: 12px; list-style:none; } #tabContainer { margin: 30px; } #tabContainer li { float: left; width: 80px; margin: 0 3px; background: #efefef; text-align: center; } #tabContainer a { display: block; } #tabContainer a.on { background: pink; } </style></head><body> <div id="tabContainer"> <ul> <li id="tab1"><a href="#" class="on" onclick="switchTab('tab1','con1');this.blur();return false;"> 命运</a></li> <li id="tab2"><a href="#" onclick="switchTab('tab2','con2');this.blur();return false;"> 运势</a></li> <li id="tab3"><a href="#" onclick="switchTab('tab3','con3');this.blur();return false;"> 缘分</a></li> <li id="tab4"><a href="#" onclick="switchTab('tab4','con4');this.blur();return false;"> 人生</a></li> </ul> <div style="clear: both"> </div> <div id="con1"> 命运是个神马玩意儿... </div> <div id="con2" style="display: none"> 霉运也是一种运气... </div> <div id="con3" style="display: none"> 缘份纯粹是蒙人的东西... </div> <div id="con4" style="display: none"> 人生就是人"生"出来之后的过程... </div> </div></body></html> 感谢大家出谋划策,可能写的时候太急了,没有描述清楚,我想实现的是类似浮动层的效果,各位看下面的例子<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>jquery浮动层</title><style type="text/css"> #Float {background-color: #000;height: 200px;width: 100px;position: absolute;top: 80px;right: 20px;}</style></head><script type="text/javascript" src="js/jquery-1.9.1.js"></script><script language="javascript"> $(document).ready(function(){ $(window).scroll(function (){ var offsetTop = $(window).scrollTop() + 80 +"px"; $("#Float").animate({top : offsetTop },{ duration:0 , queue:false }); }); }); </script> <body><div style="height:2000px;"></div><div id="Float"></div></body></html>我把想tab选项卡的可切换的部分保持浮动,但是每一个tab选项卡的内容可以随意上下滚动看看下图,当某一个tab选项卡的表单内容过多的话,我想保持tab选项卡随着滚动条的滚动而上下浮动 在这里引用四楼的选项卡切换实现选项卡固定浮动,在样式下增加/******通过CSS的position属性来控制选项卡浮动*******/ #tabContainer { height:200px; border:1px solid #ff0000; overflow:scroll; position:relative } #tabContainer ul{ position:fixed; z-index:2} #con1,#con2,#con3{ height:300px; position:absolute; overflow:scroll; z-index:1 },是这样的效果吗 有真实案例吗?同求http://www.hellbear.comhttp://www.hellbear.com/picturerecord/index.html 为何我在JS里写的A标签点击没有反应? 在javascript中如何屏蔽Crtl+Alt+Del键? 导航条被选中某项记录,怎么做有例子吗 如何拦截https请求 【等待】 firefox中如何关闭自身窗口? 什么原因会造成控件挂起? Table增加行問題,求救---求源碼 请教,javascript不会编了 createPopup创建窗口问题,请帮忙 请问我用javascript打开一个弹出式窗口后怎样将自身关闭?? javascript代码:移动到图片热区上显示边框函数未正确调用,问题出在哪里? 如何判断radio选中了哪个值
.selected{
background-color: red;
}
span{
cursor: pointer;
}
</style>
<script type="text/javascript">
function selected(obj){
for(var i = 1 ; i < 3 ; ++i){
document.getElementById('item' + i + 'content').style.display = 'none';
document.getElementById('item' + i).className = '';
}
obj.className = 'selected';
document.getElementById(obj.id + 'content').style.display = 'block';
}
</script>
<body>
<div>
<div>
<span class="selected" id="item1" onclick="selected(this)">选项卡一</span>
<span id="item2" onclick="selected(this)">选项卡二</span>
</div>
<div>
<div id="item1content">选项卡一的内容</div>
<div style="display:none;" id="item2content">选项卡二的内容</div>
</div>
</div>
</body>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
li{
float:left;
}
</style>
<script type="text/javascript">
(function(){
if(window['z']){
alert("the namespace z has been used,change anthor please");
return;
}else{
window['z']={};
}
function addTab(){
var div=document.createElement("div");
var ul=document.createElement("ul");
ul.style.marginLeft="-40px";
var show=document.createElement("div");
for(var i=0;i<arguments.length;i++){
var li=document.createElement("li");
li.style.width="100px";
li.style.textAlign="center";
li.style.listStyleType="none";
li.innerHTML=arguments[i];
li.style.backgroundColor="blue";
li.style.borderStyle="solid";
li.style.borderWidth="1px";
li.onmouseover=function(){
this.style.backgroundColor="green";
this.style.borderBottomColor='green';
show.innerHTML=this.innerHTML;
}
li.onmouseout=function(){
this.style.backgroundColor="blue";
this.style.borderBottomColor='black';
}
ul.appendChild(li);
}
show.style.width=arguments.length*102+"px";
show.style.height=arguments.length*100+"px";
show.style.clear="both";
show.style.backgroundColor="green";
div.appendChild(ul);
div.appendChild(show);
document.body.appendChild(div);
}
window['z']['addTab']=addTab;
})();
window.onload=function(){
z.addTab("1","2",'test');
}
</script>
</head><body>
</body>
</html>
??
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>tab页切换</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function switchTab(ProTag, ProBox) {
for (i = 1; i < 5; i++) {
if ("tab" + i == ProTag) {
document.getElementById(ProTag).getElementsByTagName("a")[0].className = "on";
} else {
document.getElementById("tab" + i).getElementsByTagName("a")[0].className = "";
}
if ("con" + i == ProBox) {
document.getElementById(ProBox).style.display = "";
} else {
document.getElementById("con" + i).style.display = "none";
}
}
}
</script>
<style type="text/css">
*
{
padding: 0;
margin: 0;
line-height: 25px;
font-size: 12px;
list-style:none;
}
#tabContainer
{
margin: 30px;
}
#tabContainer li
{
float: left;
width: 80px;
margin: 0 3px;
background: #efefef;
text-align: center;
}
#tabContainer a
{
display: block;
}
#tabContainer a.on
{
background: pink;
}
</style>
</head>
<body>
<div id="tabContainer">
<ul>
<li id="tab1"><a href="#" class="on" onclick="switchTab('tab1','con1');this.blur();return false;">
命运</a></li>
<li id="tab2"><a href="#" onclick="switchTab('tab2','con2');this.blur();return false;">
运势</a></li>
<li id="tab3"><a href="#" onclick="switchTab('tab3','con3');this.blur();return false;">
缘分</a></li>
<li id="tab4"><a href="#" onclick="switchTab('tab4','con4');this.blur();return false;">
人生</a></li>
</ul>
<div style="clear: both">
</div>
<div id="con1">
命运是个神马玩意儿...
</div>
<div id="con2" style="display: none">
霉运也是一种运气...
</div>
<div id="con3" style="display: none">
缘份纯粹是蒙人的东西...
</div>
<div id="con4" style="display: none">
人生就是人"生"出来之后的过程...
</div>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jquery浮动层</title>
<style type="text/css">
#Float {background-color: #000;height: 200px;width: 100px;position: absolute;top: 80px;right: 20px;}
</style>
</head>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script language="javascript">
$(document).ready(function(){
$(window).scroll(function (){
var offsetTop = $(window).scrollTop() + 80 +"px";
$("#Float").animate({top : offsetTop },{ duration:0 , queue:false });
});
});
</script>
<body>
<div style="height:2000px;"></div>
<div id="Float"></div>
</body>
</html>
我把想tab选项卡的可切换的部分保持浮动,但是每一个tab选项卡的内容可以随意上下滚动看看下图,当某一个tab选项卡的表单内容过多的话,我想保持tab选项卡随着滚动条的滚动而上下浮动
实现选项卡固定浮动,在样式下增加/******通过CSS的position属性来控制选项卡浮动*******/
#tabContainer
{
height:200px;
border:1px solid #ff0000;
overflow:scroll;
position:relative
}
#tabContainer ul{ position:fixed; z-index:2}
#con1,#con2,#con3{ height:300px; position:absolute; overflow:scroll; z-index:1 },是这样的效果吗
有真实案例吗?同求
http://www.hellbear.comhttp://www.hellbear.com/picturerecord/index.html