js實(shí)現(xiàn)鼠標(biāo)單擊Tab表單切換效果
更新時(shí)間:2018年05月16日 16:17:14 投稿:lijiao
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)鼠標(biāo)單擊Tab表單切換效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了js實(shí)現(xiàn)鼠標(biāo)單擊Tab表單切換展示的具體代碼,供大家參考,具體內(nèi)容如下
代碼:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
*{
padding: 0;
margin: 0;
border:0;
}
body{
text-align: center;
}
ul{
list-style: none;
}
a{
text-decoration: none;
color: #ff6666;
font-family: Arial;
}
.tab-container{
width: 398px;
height: 200px;
border:1px #ffcccc solid;
margin: 0 auto;
position: relative;
overflow: hidden;
}
/*tab-head begin*/
.tab-head{
width: 400px;
height:30px;
left:0;
background: #ffcccc;
position: absolute;
left:-1px;//這里設(shè)置-1是為了li的border與最外層的border重合
}
.tab-head li{
float:left;
height: 29px;
line-height: 29px;
width: 78px;
overflow: hidden;
padding: 0 1px;
border-bottom: 1px solid #ffcccc;
background: #ffeeee;
}
li.select{
background: #fff;
padding: 0;
border-left: 1px solid #ffcccc;
border-right: 1px solid #ffcccc;
border-bottom: 1px solid #fff;
}
/*tab-head end tab-panel begin*/
.tab-panel{
position: relative;
width: 100%;
height: 85%;
top: 15%;
-webkit-transition:all 0.01s linear;//切換過渡效果
}
.tab-panel section{
position: absolute;
display: inline-block;
width: 100%;
height: 100%;
}
#panel-1{
left: 0;
}
#panel-2{
left: 100%;
}
#panel-3{
left: 200%;
}
#panel-4{
left: 300%;
}
#panel-5{
left: 400%;
}
</style>
</head>
<body>
<div class="tab-container">
<ul class="tab-head">
<li id="1" class="select" onmousedown="$(this)"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Tab1</a></li>
<li id="2" onmousedown="$(this)"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Tab2</a></li>
<li id="3" onmousedown="$(this)"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Tab3</a></li>
<li id="4" onmousedown="$(this)"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Tab4</a></li>
<li id="5" onmousedown="$(this)"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >Tab5</a></li>
</ul>
<div id="tab-panel" class="tab-panel">
<section id="panel-1"><p>這是panel-1</p></section>
<section id="panel-2"><p>這是panel-2</p></section>
<section id="panel-3"><p>這是panel-3</p></section>
<section id="panel-4"><p>這是panel-4</p></section>
<section id="panel-5"><p>這是panel-5</p></section>
</div>
</div>
<script type="text/javascript">
function $(id){
var lis = document.getElementsByTagName('li');
for (var i = 0; i < lis.length; i++) {
lis[i].setAttribute('class','');
};
id.setAttribute('class','select');
var ele = document.getElementById('tab-panel');
ele.style.left=-(id.id-1)+'00%';
}
</script>
</body>
</html>
效果圖:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- javascript實(shí)現(xiàn)tab切換的四種方法
- 一個(gè)精簡的JS DIV層tab切換代碼
- js(JavaScript)實(shí)現(xiàn)TAB標(biāo)簽切換效果的簡單實(shí)例
- javascript實(shí)現(xiàn)tabs選項(xiàng)卡切換效果(自寫原生js)
- 一個(gè)js的tab切換效果代碼[代碼分離]
- 用AngularJS的指令實(shí)現(xiàn)tabs切換效果
- 基于jquery的tab切換 js原理
- Vue.js組件tabs實(shí)現(xiàn)選項(xiàng)卡切換效果
- javascript仿126郵箱TAB切換效果
- js實(shí)現(xiàn)點(diǎn)擊切換TAB標(biāo)簽實(shí)例
相關(guān)文章
chrome瀏覽器如何斷點(diǎn)調(diào)試異步加載的JS
chrome瀏覽器不僅僅可以用來上網(wǎng),對(duì)于開發(fā)人員來說,它更像是一款強(qiáng)大的開發(fā)輔助工具。今天這篇文章給大家分享在chrome瀏覽器如何斷點(diǎn)調(diào)試異步加載的JS,有需要的可以參考借鑒。2016-09-09
通過繼承IHttpHandle實(shí)現(xiàn)JS插件的組織與管理
最近,項(xiàng)目中的用到的Js插件越來越多,有的是用原生javascript寫的,有的是調(diào)用的jquery插件,頁面上Js和Css文件的引用也越來越混亂,而且Js文件之間還有引用先后的依賴關(guān)系2010-07-07
Easyui Tree獲取當(dāng)前選擇節(jié)點(diǎn)的所有頂級(jí)父節(jié)點(diǎn)
這篇文章主要介紹了Easyui Tree獲取當(dāng)前選擇節(jié)點(diǎn)的所有頂級(jí)父節(jié)點(diǎn),以及easyUI Tree顯示選中節(jié)點(diǎn)的所有父節(jié)點(diǎn)的實(shí)現(xiàn)代碼,需要的朋友可以參考下2017-02-02
基于JS實(shí)現(xiàn)文字轉(zhuǎn)語音即文本朗讀
這篇文章主要為大家詳細(xì)介紹了JavaScript如何利用SpeechSynthesis實(shí)現(xiàn)文字轉(zhuǎn)語音即文本朗讀的功能,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下2023-10-10
關(guān)于JavaScript 數(shù)組你應(yīng)該知道的事情(推薦)
這篇文章主要介紹了JavaScript 數(shù)組,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04

