Prinzhorn / skrollr-menu

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

Page is loading at the top of the window. Hash URLs rendered useless when going to links. Help! #32

Open sdawson26 opened 10 years ago

sdawson26 commented 10 years ago

If I'm on the root page "/" and click an anchor such as "/#link", the skrollr takes me there just fine. However, when I go to the actual /#link URL, it jumps back to the top of the page right after loading. Something in my skrollr.menu.init function seems to be doing the problem:

My project: http://prbbi.com/services/pr/test/

So for example, if you go to this link, it jumps back to the top of the page after loading: http://prbbi.com/services/pr/test/#reports

Prinzhorn commented 10 years ago

Please include the unminified sources. It's impossible to debug otherwise.

By the way it doesn't happen in Firefox for me, only Chrome.

sdawson26 commented 10 years ago

Prinzhorn,

Sorry about that. I've updated both Skrollr and Skrollr-menu to unminified.

Here is the file I'm calling the init from:

http://prbbi.com/js/pr/pr-footer.js

Prinzhorn commented 10 years ago

This was introduced by https://github.com/Prinzhorn/skrollr-menu/commit/ebb39bba#diff-14e11108e3fcf79bc01a46d211744495R141

I'm not sure though why I thought it would be a good idea to fall back to 0 when the popstate event doesn't deliver any data. For some reason Chrome does fire a popstate when the page loads. I'm not sure about the consequences of ignoring popstate events which lack skrollr-menu specific data (which are the the counterpart to a skrollr-menu triggered pushstate).

Prinzhorn commented 10 years ago

Reading through #3 again maybe http://stackoverflow.com/questions/10742422/prevent-browser-scroll-on-html5-history-popstate was the reason for that. Because if I remove that code, then Chrome will scroll to the anchor by itself, which is not desired especially on mobile where this would break the page...

Prinzhorn commented 10 years ago

I'd need to take a closer look at this, but I'm busy. Maybe someone can play around with it and see what happens if the popstate is ignored, if it doesn't contain skrollr data.

ir-Sindaco commented 10 years ago

I am having the same exact issue, but i am not good enough to work out a solution. Hope someone can find a workaround soon! edit: btw i am on a very tight schedule and need a fix asap (i would also gladly donate for the work if needed!) i got some results simply by deleting the word "popstate" in the script, but then i get this: when clicking on an anchor from the first page menu (like productivity-and-performance-services.php#tire-pressure) i get to the correct section in the second page, but if i am already on the 2nd page and click the same link "productivity-and-performance-services.php#tire-pressure" it gets to a wrong position... while having a link and clicking #tire-pressure on the same 2nd page would work ok. I could find a workaround to this as well (different links on different pages, so when i am on the 2nd page the menu links will point just to the #tire-pressure and not to the full productivity-and-performance-services.php#tire-pressure link) but there must be a better way. Also removing "popstate" might have side effects i am not aware of. ..hope i explained well enough!

eudes commented 10 years ago

Same issue here: http://eudes.es/nova/test/index.html#organizar-evento When loaded, page jumps to hash and immeditely afterwards jumps to the top. Also, on mobile chrome there's a different issue: When loaded the page jumps to hash, but you can't scroll up from there, only down. The size of the frame is the usual (whole page), but on the top of the page is the hashed position so you have half a blank page from the footer down.

tslatt commented 9 years ago

Has anyone found a solution yet?