The original jquery:
$('#container section').each(function() {
$(this).waypoint(function(direction) {
var anchorRef = 'a[href="#' + this.id + '"]';
if (direction === 'down') {
$(anchorRef).animate({'backgroundColor' : 'rgb(230, 77, 78)'});
} else {
$(anchorRef).animate({'backgroundColor' : 'rgb(25, 25, 25)'});
}
});
});
The CSS:
.main-menu ul li a:hover {
background-color: #333;
}
The problem is that, once that animation finishes, if we return to that element, the hover effect doesn't get applied any longer.
Any clue why?
I've tried to "force" the overstate on the script like this:
$('#container section').each(function() {
$(this).waypoint(function(direction) {
var anchorRef = 'a[href="#' + this.id + '"]';
var anchorRefHover = 'a[href="#' + this.id + '"]:hover';//NEW
if (direction === 'down') {
$(anchorRef).animate({'backgroundColor' : 'rgb(230, 77, 78)'});
$(anchorRefHover).css({backgroundColor : '#333'});//NEW
} else {
$(anchorRef).animate({'backgroundColor' : 'rgb(25, 25, 25)'});
$(anchorRefHover).css({backgroundColor : '#333'});//NEW
}
});
});
Still lost the hover effect market on the CSS.
I added !important on the CSS hover rule. That triggers the hover. But the reason while I prefer doing it using javascript its because, the hover background color should only apply if the element we have hover doesn't have the background rgb(230, 77, 78)
Not sure if it will work, but I'm thinking about adding !important via javascript when the above is the case... but perhaps there's a better way?
Any clue to help me out?
Note: Here's the Fiddle thanks to koala_dev efford:
normalto the element, and trigger the hover on that class. Then you toggle that class after animation. eg.main-menu ul li a.normal:hover { background-color: #333; }and$(anchorRef).toggleClass('normal');