I have a function that checks if the URL contains any of navigation hrefs every 100ms and if it does, the certain elements get class active added.
Code:
var checkActive = function(){
var path = window.location.pathname,
path = decodeURI(path),
path = path.replace(/[\/]/, "");
if ( window.location.pathname.indexOf(path) > -1 ) {
$('.navigation .nav li a[href*="' + path + '"]').parent().addClass('active');
$('.navigation .nav li a:not([href*="'+path+'"])').parent().removeClass('active');
}
(function loopingFunction() {
checkActive();
setTimeout(loopingFunction, 100);
})();
Is this checking every 100ms going to affect the performance for other user with weaker PC's ?
P.s: I used this method since I'm using pushState, statechange and .load() to get my content updated, therefore the page itself doesn't refresh.