滚动菜单活动类 - 如何在活动类上添加字体颜色和字体大小更改?

时间:2014-08-07 18:12:42

标签: javascript html css drop-down-menu menuitem

我在滚动时将活动状态添加到我的菜单中。

HTML:

<li><a href="#subsection-schedule"><span class="blueNavTitle">CONTENT</span></a>
    <ul>
        <li><a id="nav_section2" href="#A" class="active">A</a></li>
        <li><a id="nav_section3" href="#B">Upload</a></li>
        <li><a id="nav_section4" href="#C">Add</a></li>
        <li><a id="nav_section5" href="#D">Add MORE</a></li>
        <li><a id="nav_section6" href="#E">Prepare</a></li>
        <li><a id="nav_section7" href="#F">Present</a></li>
        <li><a id="nav_section8" href="#G">Upload MORE/a></li>
        <li><a id="nav_section9" href="#K">Increase</a></li>
    </ul>
</li>

JavaScript:

<script type="text/javascript">
$(function(){
var menusections = {},
    _height  = $(window).height(),
    i        = 0;

// Grab positions of our sections 
$('.menusection').each(function(){
    menusections[this.name] = $(this).offset().top;
});

$(document).scroll(function(){
    var $this = $(this),
        pos   = $this.scrollTop();
    // Look in the sections object and see if any section is viewable on the screen. 
    // If two are viewable, the lower one will be the active one.     
    for(i in menusections){
        if(menusections[i] > pos && menusections[i] < pos + _height){
            $('a').removeClass('active');
            $('#nav_' + i).addClass('active');
        } 

    }
});
}); 
 </script>

活跃的CSS是:

.active {
background-color: rgba(0, 0, 0, 0.1);
 }

我的问题是,除了背景颜色变化之外,如果我想更改字体大小和字体颜色怎么办?我尝试添加font-size和其他一些但不起作用。

1 个答案:

答案 0 :(得分:2)

只需添加到您的css类:

.active {
background-color: rgba(0, 0, 0, 0.1);
font-size:14pt !important; /*whatever size you want*/
color:blue !important; /*(font color)*/
}