jquery css 主菜單樣式的跳轉

來源:互聯網
上載者:User

jquery css 主菜單樣式的跳轉

想要實現的效果其實是挺常見的那種:網頁的主菜單一開始有一種預設的樣式(如A樣式),當滑鼠經過某一功能表項目時,此功能表項目會套用一種樣式(如B樣式),當滑鼠點擊某一功能表項目時,當前功能表項目會套用B樣式,其餘功能表項目會去掉B樣式而套用預設的A樣式。經過嘗試,寫出了比較簡單的代碼,存下來,以備後用。

 

html代碼:

 

 
  • Home
  • Download
  • Documentation
  • Community
  • Success Stories
  • News
  • Events
  • About

css代碼:

 

 

#menuBar{clear:both;width:1200px;margin:0 auto;color:#efefef;font-family:Arial;font-size:18px;}#menuBar ul{list-style:none;height:55px;margin:0px;padding:0px;}.beforeClick{float:left;width:150px;text-align:center;line-height:55px;height:55px;background-image:url(Welcome%20to%20Python.org_files/20141021190636.png);background-repeat:repeat-x;margin-top:10px;}.beforeClick:hover{background-color:3776ab;border:1px solid #aaa;height:53px;line-height:53px;width:148px;background-image:none;cursor:pointer;}.clickedMenu{background-color:3776ab;border:1px solid #aaa;height:53px;line-height:53px;width:148px;background-image:none;cursor:pointer;}

js代碼:

 

 

<script>$(function(){$(#menuBar ul li).each(function() {        $(this).addClass(beforeClick); // 最開始,讓所有節點都加上beforeClick樣式    });});$(function(){$(#menuBar ul li).each(function(i) {$(this).click(function(){$(this).siblings(li).removeClass(clickedMenu); //讓其餘兄弟節點去掉clickedMenu樣式,即點擊後的菜單樣式$(this).siblings(li).addClass(beforeClick); // 再讓其餘兄弟節點添加上點擊前的樣式beforeClick$(this).addClass(clickedMenu);// 給當前節點添加上clickedMenu樣式。})});})</script>

:

 

1、初始狀態:

2、滑鼠經過某一功能表項目時的狀態:

3、滑鼠點擊某一菜單後,並且滑鼠經過其它功能表項目時的狀態:

3、當再次點擊其它菜單時,樣式繼續發生變化:

聯繫我們

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