基於javascript實現最簡單的選項卡轉場效果_javascript技巧

來源:互聯網
上載者:User

本文執行個體為大家分享了js選項卡轉場效果的具體實現代碼,供大家參考,具體內容如下

<!DOCTYPE html><html><head><meta charset="gb2312" /><title>朱朱製作</title><script src="js/jquery.js" type="text/javascript"></script><style>  *{    margin: 0;    padding: 0;  }  body{    background-color: #fff;    font-family: "微軟雅黑";    font-size: 18px;    width: 1000px;    margin: 50px auto;    color:#000000;  }  .wrapper{    width: 350px;  }  #nav ul{    border-bottom: 2px solid yellowgreen;    height: 32px;  }  #nav li{    display: inline-block;    border: 2px solid #999;    border-bottom: none;    margin-left: 10px;    width: 65px;    text-align: center;    line-height: 30px;  }  #nav li:hover{    cursor: pointer;  }  #content{    display: block;    border: 1px solid blue;    border-top: none;    text-align: center;    height: 100px;    line-height: 100px;  }  #nav li.on{    border-bottom: solid 2px #ffffff;  }  .hide{    display: none;  }  .show{    display: block;  }</style></head><script type="text/javascript">  /*window.onload=change; //js代碼實現  function change(){  this.nav=document.getElementById("nav");  this.li=nav.getElementsByTagName("li");  this.cont=document.getElementById("content");  this.divi=cont.getElementsByTagName("div");  for(var i=0;i<li.length;i++){    li[i].index=i;    li[i].onclick=function(){      for(var i=0;i<li.length;i++){      li[i].className="";      divi[i].className="hide";      }    li[this.index].className="on";    divi[this.index].className="show";    }  }}*/$(function(){$('#nav li').each(function(){  $(this).click(function(){    $('#nav li').removeClass("on");    $(this).addClass("on");    $("#content div").removeClass();    $("#content div").eq($(this).index()).addClass("show").siblings().addClass("hide");})})})</script><body>  <div class="wrapper">    <div id="nav">      <ul>        <li class="on">num1</li>        <li>num2</li>        <li>num3</li>        <li>num4</li>      </ul>    </div><div id="content">      <div class="show">content1</div>      <div class="hide">content2</div>      <div class="hide">content3</div>      <div class="hide">content4</div>    </div>  </div></body></html>

以上就是本文的全部內容,希望對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.