簡體   English   中英

活動頁面的動態下划線

[英]Dynamic underlining of active page

剛才問了一個類似的問題並試圖建立我的答案,但我仍然遇到麻煩。

我有一個導航菜單,鏈接到頁面內的不同位置。 我希望活動窗格的鏈接加下划線。 請參閱jsFiddle進行演示。 return false是代碼的必要部分。 我有一個javascript函數引導頁面到位置而不是立即跳轉到它。

謝謝!

http://jsfiddle.net/danielredwood/aBuZu/3/

HTML

<div id="nav">
    <a href="#about" id="nav_about">ABOUT</a><br />
    <a href="#pictures" id="nav_pictures">PICTURES</a><br />
    <a href="#contact" id="nav_contact">CONTACT</a>
</div>

CSS

a, a:active, a:visited {
    color:#1d1d1d;
    text-decoration:none;
}
a:hover {
    text-decoration:underline;
}

JavaScript的

$('#nav a').click(function(){
    $('#nav a').css('text-decoration', 'none', function(){
        $(this).css('text-decoration', 'underline');
    });
    return false;
});

試試這個http://jsfiddle.net/aBuZu/1/

 $('#nav a').click(function(){
    $('#nav a').css("textDecoration", "none"); 
    $(this).css('textDecoration', 'underline');
    return false;
 });

更輕松:

$('#nav a').click(function(event) {
    event.preventDefault(); //same as return false
    $('#nav a').removeClass('active');        
    $(this).toggleClass('active');   
});

CSS:

a {
    color:#1d1d1d;
    text-decoration:none;
}
a:hover, a.active {
    text-decoration:underline;
}
$(this).css('color', 'underline');

有點胡說八道。 也許顏色應該是文字裝飾: 例子

$('#nav a').click(function(e){
    $('#nav a').css('text-decoration', 'none');
    $(this).css('text-decoration', 'underline');
    e.preventDefault();
});

首先,您需要在jsFiddle中選擇框架jQuery

更新了JS

$('#nav a').click(function(){
    $('#nav a').css('text-decoration', 'none');
    $(this).css('text-decoration', 'underline');
    return false;
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM