jQuery-One-Page-Nav
jQuery-One-Page-Nav copied to clipboard
Changing url on scroll [SOLVED]
Added a command changing the url on scroll. It's adding the name (the id) of the current focused section to the url each time you scroll. Since several people seem to need it, it could be adjusted in future versions.
In this part:
scrollChange: function() {
var windowTop = this.$win.scrollTop();
var position = this.getSection(windowTop);
var $parent;
//If the position is set
if(position !== null) {
$parent = this.$elem.find('a[href$="#' + position + '"]').parent();
//If it's not already the current section
if(!$parent.hasClass(this.config.currentClass)) {
//Change the highlighted nav item
this.adjustNav(this, $parent);
//If there is a scrollChange callback
if(this.config.scrollChange) {
this.config.scrollChange($parent);
}
}
}
},
just add the following lines:
scrollChange: function() {
var windowTop = this.$win.scrollTop();
var position = this.getSection(windowTop);
var $parent;
//If the position is set
if(position !== null) {
$parent = this.$elem.find('a[href$="#' + position + '"]').parent();
//If it's not already the current section
if(!$parent.hasClass(this.config.currentClass)) {
//Change the highlighted nav item
this.adjustNav(this, $parent);
// ADD THIS TWO LINES TO CHANGE THE URL ON SCROLL ! var theHash = position; window.location.hash = theHash;
//If there is a scrollChange callback
if(this.config.scrollChange) {
this.config.scrollChange($parent);
}
}
}
},
Best regards, Rechtsamwald