Bray
Bray

Reputation: 361

Menu active class on scrolling - How to add font color and font size change on active class?

I've added the active state to my menu on scrolling.

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>

The CSS for active is:

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

My question is, what if I want to change the font-size and font-color in addition to the background color change? I tried adding font-size and some others but are not working.

Upvotes: 0

Views: 405

Answers (1)

Ljungren
Ljungren

Reputation: 177

Just add to your css class:

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

Upvotes: 2

Related Questions