JS實現完全語義化的網頁選項卡效果代碼_javascript技巧

來源:互聯網
上載者:User

本文執行個體講述了JS實現完全語義化的網頁選項卡效果代碼。分享給大家供大家參考。具體如下:

這是一款完全語義化的JS網頁選項卡,包括了兩種用法,一種是點擊式,另一種是滑動門式,具體用哪一種要根據你自己的需要了,滑動門是在滑鼠經過時觸發,選項卡則是需要滑鼠點擊的。

運行效果截圖如下:

線上示範地址如下:

http://demo.jb51.net/js/2015/js-yyh-web-tab-cha-nav-codes/

具體代碼如下:

<!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>語義化的網頁選項卡</title><style type="text/css"> *{margin:0;padding:0;font-size:13px;line-height:1.5;} body{padding:20px;} .cur{color:#f60;border-bottom:1px solid #fff;font-weight:bold;background:#fff;cursor:default;} #tab_,dl{position:relative;float:left;height:100px;width:300px;} h4,dt{float:left;height:20px;margin:0 0 0 8px;display:inline;line-height:20px;width:60px;border:1px solid #ccc;position:relative;z-index:11;text-align:center;font-weight:normal;cursor:pointer;background:#eee;} .c,dd{position:absolute;top:21px;border:1px solid #ccc;left:0;width:250px;padding:20px;overflow:hidden;display:block;} #tab_{clear:left;} h1{clear:left;padding:10px 0} #tab_1.cur{color:#f60} #tab_2.cur{color:blue} #tab_3.cur{color:green}</style></head><body><h1>mouseover</h1><dl id="tab"> <dt>美國</dt> <dd>我都不怕</dd> <dt>朝鮮</dt> <dd>誰都怕我</dd> <dt>某國</dt> <dd>我誰都怕</dd></dl><h1>click</h1><div id="tab_"> <h4>orange</h4> <div class="c">桔紅</div> <h4>blue</h4> <div class="c">藍色</div> <h4>green</h4> <div class="c">綠色</div></div><script type="text/javascript">function id(elem) {return document.getElementById(elem)}function show(elem) {elem.style.display = "";}function hide(elem) {elem.style.display = "none";}function next( elem ) { do { elem = elem.nextSibling; } while ( elem && elem.nodeType != 1 ); return elem;}function tab(a, p) { var p = (p === undefined) ? {e:"onclick",n:1} : p,  node = id(a).firstChild,  x = []; p.e = (p.e === undefined) ? "onclick" : p.e; p.n = (p.n === undefined) ? 1 : p.n; node=(node.nodeType !== 1)?next(node):node; for (var i = 1, node; node; i++, node = next(node)) {  x[i] = node; } for (var i = 1; x[i]; i++) {  if(i % 2 == 0){hide(x[i]);x[i-1].id=a+(i/2)}  x[p.n*2-1].className = "cur";  show(x[p.n*2]);  temp = function (i) {   if (i % 2 == 1) {    x[i][p.e] = function () {     for (var j = 1; x[j]; j++) {      if (j % 2 == 0) {       hide(x[j]);       x[j-1].className = ""      }     }     show(x[i+1]);     x[i].className = "cur"    }   } else {    return null   }  }(i) }}tab("tab",{e:"onmouseover",n:2});tab("tab_")</script></body></html>

希望本文所述對大家的JavaScript程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.