Scroll to Anchor on Same Page
-
Hi everyone,
I’m right now helping out a colleague with his one page layout in LayTheme. He loves it!
Since it’s a one-pager he wanted to have a “about” in the menu and make that scroll down to the section with the respective anchor.
We already setup everything following this topic:
http://laythemeforum.com:4567/topic/2863/link-to-anchor-from-another-page/4So it’s all working now when the user visits
http://tldomain.com#about
the site loads and then smoothly scrolls down to the anchor. But when the user is on the front page and clicks on the about link in the menu the hole page just snaps to the anchor point w/o any smooth sroll transition.<script> window.laytheme.on('newpageshown', function(){ if(window.location.hash.length > 0){ var id = window.location.hash; if(jQuery(id).length > 0){ jQuery('html, body').animate( { scrollTop: jQuery(id).offset().top }, { duration: 1200 }); } } }); </script>
I'm sorry if this has been solved already somewhere in the forum. I was unable to find a good solution, though.
Any help is very much appreciated!
-
Dear @edgrbnz
the code you show us here does the following:- see if there is a # in the url
- scroll to the id behind the #
- animate the scrolling
It is not for when you click on a link.
You need another function for this.I have those two threads bookmarked. I hope you can find a solution there.
ANCHOR LINK
http://laythemeforum.com:4567/topic/2863/link-to-anchor-from-another-page/4SMOOTH LINK
http://laythemeforum.com:4567/topic/2144/fade-effect-smooth-transitions-links-via-custom-html/2Otherwise let us know.
Best!
Marius
-
Dear @edgrbnz
ah great! Thank you for sharing.Yes, even though things do not get recognized – they get recognized :-)
Best!
Marius
Before you post:
- When using a WordPress Cache plugin, disable it or clear your cache.
- Update Lay Theme and all Lay Theme Addons
- Disable all Plugins
- Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"
This often solves issues you might run into
When you post:
- Post a link to where the problem is
- Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
- If the problem is difficult to explain, post screenshots / link to a video to explain it