Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Change location.hash *before* scrolling. #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions jquery.nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,26 @@
//Removing the auto-adjust on scroll
self.unbindInterval();

//Do we need to change the hash?
if(self.config.changeHash) {
// We need to insert a temp. link element to avoid breaking
// the broweser history.
var elem = document.getElementById(id);
var $a = $('<a> </a>').attr('id', id).css({
position: 'absolute',
top: $(window).scrollTop(),
left: $(window).scrollLeft()
});

elem.id = '';
$('body').prepend($a);
location.hash = newLoc;
$a.remove();
elem.id = id;
}

//Scroll to the correct position
self.scrollTo(newLoc, function() {
//Do we need to change the hash?
if(self.config.changeHash) {
window.location.hash = newLoc;
}

//Add the auto-adjust on scroll back in
self.bindInterval();

Expand Down Expand Up @@ -220,4 +233,4 @@
});
};

})( jQuery, window , document );
})( jQuery, window , document );