給導覽列添加停留樣式,導覽列添加停留樣式

來源:互聯網
上載者:User

給導覽列添加停留樣式,導覽列添加停留樣式

淺談下給類似導覽列的東東,添加停留樣式的三種方法:

執行個體:

HTML代碼:

 <div class="side_layout">      <!--Sidebar content-->      <div class="list-group">      <a href="#" class="list-group-item active">項目1 <span class="glyphicon_right_img glyphicon glyphicon-chevron-right"></span></a>        <a href="#" class="list-group-item">項目2 <span class="glyphicon_right_img glyphicon glyphicon-chevron-right"></span></a>        <a href="#" class="list-group-item">項目3 <span class="glyphicon_right_img glyphicon glyphicon-chevron-right"></span></a>        <a href="#" class="list-group-item">項目4 <span class="glyphicon_right_img glyphicon glyphicon-chevron-right"></span></a>        <a href="#" class="list-group-item">項目5 <span class="glyphicon_right_img glyphicon glyphicon-chevron-right"></span></a>        <a href="#" class="list-group-item">項目6 <span class="glyphicon_right_img glyphicon glyphicon-chevron-right"></span></a>      </div>    </div>
js代碼:

方法一:

$(function(){$(".side_layout a").click(function(){$(this).addClass('active');$(this).siblings().removeClass('active');});   });方法二:$(document).on("click", ".side_layout a", function(){$(this).addClass('active').siblings().removeClass('active');});方法三:$(function(){$(".side_layout a").bind('click',function(){$(this).addClass('active');$(this).siblings().removeClass('active');});    });
個人認為方法二最方便。

方法一和三都需要包含在$(function()內部

方法二、三都是給元素繫結一個單擊事件,區別在於$(document).on的方法是把綁定委託到了文檔上,二bind方法是委託到了.side_layout a上,據查閱資料,前者效率更好~~~





怎動態設定導覽列被選中的當前樣式

代碼注釋
!important 可以提升指定樣式規則的應用優先權
width:111px!important 整個菜單的寬度
width:80px!important 菜單串連的寬度
top:234px整個菜單的位置,即距頂部距離為234px
height:222px!important可以根據需要自己調節高度
line-height:15px!important與height:15px!important 是對應的,也可以根需要自己需要設定菜單與菜單之間的位置排列規則
 
怎用jquery給導航條隨著頁面加個樣式?

點擊“首頁”或者“熱門推薦”這些導航不是跳轉頁面嗎,都跳轉到另外一個頁面了.那些動作也就起不了效果了,這些是後台判斷的。希望能幫到你,如果不是點擊跳轉,我再幫你寫個JQ.
 

聯繫我們

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