I've got a jQuery/JavaScript script for a menu that uses icons as well as label text. When the icon or text is clicked, it turns blue, until such time as another icon is clicked. Also, the page scrolls down to the relevant div on the page, but the menu bar still stays fixed along the top of the screen.
I've created several versions of this script and this is the most efficient (least code) I have managed so far.
Can anyone tell me any methods to use instead, or any other way I could make it more efficient?
window.onload = function() {
[].forEach.call(document.querySelectorAll('.navico'), function(el) {
el.addEventListener('click', imageButtonClickHandler);
});
function imageButtonClickHandler()
{
switch(this.id)
{
case "aboutnav":
grey();
$('#abouttitle').css('color', 'blue');
$('#a').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#about").offset().top - 90 }, 2000);
break;
case "routenav":
grey();
$('#routetitle').css('color', 'blue');
$('#b').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#route").offset().top - 90 }, 2000);
break;
case "enternav":
grey();
$('#entertitle').css('color', 'blue');
$('#c').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#enter").offset().top - 90 }, 2000);
break;
case "racedaynav":
grey();
$('#racedaytitle').css('color', 'blue');
$('#d').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#raceday").offset().top - 90 }, 2000);
break;
case "gallerynav":
grey();
$('#gallerytitle').css('color', 'blue');
$('#e').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#gallery").offset().top - 90 }, 2000);
break;
case "newsnav":
grey();
$('#newstitle').css('color', 'blue');
$('#f').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#news").offset().top - 90 }, 2000);
break;
case "resultsnav":
grey();
$('#resultstitle').css('color', 'blue');
$('#g').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#resu").offset().top - 90 }, 2000);
break;
case "contactnav":
grey();
$('#contacttitle').css('color', 'blue');
$('#h').css('color', 'blue');
$('html, body').animate( { scrollTop: $("#contact").offset().top - 90 }, 2000);
break;
}
}
};
function grey()
{
$('.sectitle').css('color', 'grey');
$('.roger').css('color', 'grey');
return;
}