js實現(xiàn)鼠標單擊Tab表單切換效果
更新時間:2018年05月16日 16:17:14 投稿:lijiao
這篇文章主要為大家詳細介紹了js實現(xiàn)鼠標單擊Tab表單切換效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了js實現(xiàn)鼠標單擊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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
通過繼承IHttpHandle實現(xiàn)JS插件的組織與管理
最近,項目中的用到的Js插件越來越多,有的是用原生javascript寫的,有的是調(diào)用的jquery插件,頁面上Js和Css文件的引用也越來越混亂,而且Js文件之間還有引用先后的依賴關(guān)系2010-07-07Easyui Tree獲取當前選擇節(jié)點的所有頂級父節(jié)點
這篇文章主要介紹了Easyui Tree獲取當前選擇節(jié)點的所有頂級父節(jié)點,以及easyUI Tree顯示選中節(jié)點的所有父節(jié)點的實現(xiàn)代碼,需要的朋友可以參考下2017-02-02關(guān)于JavaScript 數(shù)組你應(yīng)該知道的事情(推薦)
這篇文章主要介紹了JavaScript 數(shù)組,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-04-04