Prinzhorn / skrollr-menu

skrollr plugin for hash navigation
MIT License
285 stars 143 forks source link

Anchors do not have own permalink #3

Closed johnfisherman closed 11 years ago

johnfisherman commented 11 years ago

When clicking on a menu entry, besides moving the viewport to the actual anchor, #anchor should also be added to the url, for future permalink reference.

Right?

Prinzhorn commented 11 years ago

Yep, it's planned. Sounds easier than it is (pushstate, onpopstate, etc.).

johnfisherman commented 11 years ago

Great, good to know. It is a standard-breaker, thus an important implementation.

That said, huge kudos for both skrollr and the plugin ecosystem!

nwhite89 commented 11 years ago

I had a quick look at this is it not possible to add

window.location.hash = href.substr(1);

after the test to check if it is a hashlink? This fix will only work in IE8+ as far as I am aware so this might not be a viable option?

Prinzhorn commented 11 years ago

This will cause the browser to jump to said hash.

nwhite89 commented 11 years ago

I have tried it my self and it simply changes without doing anything (tested in chrome and firefox) unless you can think of a browser that this will occur?

Prinzhorn commented 11 years ago

Tried it in FF and Chrome and it does what I said.

nwhite89 commented 11 years ago

hmm ok bit odd not doing it on mine have tried a few different computers and IE7+

mcmedia79 commented 11 years ago

I've added the window.location.hash = href.substr(1); in the handleClick function and it works fine in almost all browsers except mobile safari... Well at least the back button on mobile works fine but no animation.

A mix between scroll.menu and this library would be awesome http://benalman.com/projects/jquery-bbq-plugin/

By the way, great job on skrollr!

Prinzhorn commented 11 years ago

I've added it to this line https://github.com/Prinzhorn/skrollr-menu/blob/master/src/skrollr.menu.js#L62 and the following happens when I try it

this happens in both Firefox and Chrome on Ubuntu.

mcmedia79 commented 11 years ago

Forgot to tell, i'm only using data-menu-top instead of anchors nav. Works better with my skrollr animation.

This way I have an anchor that works with the back button and animation that gets right where i want. But the back button doesn't anime on safari mobile.

nwhite89 commented 11 years ago

I have done some further looking into this, when my items are easing in from the side it doesn't jump however, when scrolling downwards it does. seems very odd why to me personally

DarekC commented 11 years ago

Hi This seems to be great enhancement. Isn't it as simple as adding just line after var scrollTarget = document.getElementById(href.substr(1)); ?

window.history.pushState(href, scrollTarget, href);

For modern browsers i assume. Or it's lack something a can't see? Which is possible - i'm a beginner.

Prinzhorn commented 11 years ago

For modern browsers i assume. Or it's lack something a can't see? Which is possible - i'm a beginner.

On first sight it might look like it's that simple (it's not that hard either).

But

Prinzhorn commented 11 years ago

Was finally trying to get this implemented, but http://stackoverflow.com/questions/10742422/prevent-browser-scroll-on-html5-history-popstate

So basically it won't work the way I wanted it to.

johnfisherman commented 11 years ago

Good stuff, Alex! Well done, and thanks for this.