I'm using jQuery and the fragment identifier to create a state change depending on which part of a one-page site the user is currently looking at.
I've finally got this to work but as both Safari and Chrome won't display the fragment identifier I can't make it into a variable and therefore the system breaks down.
Is there a way to force this action specifically for WebKit browsers or another way to access the fragment?
edit: added code below
(function($){
$.fn.sectionMove = function() {
return this.each(function() {
$(this).click(function() {
if(window.location.hash){
var $hash = window.location.hash;
} else if (!window.location.hash) {
var $hash = '#section1';
}
$n = $hash.substring($hash.length-1,$hash.length);
$("div#headerNav ul li:nth-child(" + $n + ") a").removeClass('on');
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 1000,'easeInOutExpo', function(){
var $hash = window.location.hash;
$n = $hash.substring($hash.length-1,$hash.length);
$("div#headerNav ul li:nth-child(" + $n + ") a").addClass('on');
});
event.preventDefault();
});
});
};
})(jQuery);