javascript - Scroll position bug on one page website -
I am having a problem with which the scroll position is not going to the same section of the page when the external link .
For example, when attempting to access this raw URL, then the page of that section will be considered for loading. Although what happens, it scrolls in between the Gormamsan and the gift section.
This works perfectly when a similar link is used from website side navigation, for example, then click on RSVP menu item and you will see that it actually goes to the related section .
I have checked to see if there are any JS or other errors on the page, but
Thank you in advance.
Leo
== ================================= ================================================== =
code example
jQuery (document) .ready (function ($) {
function single () {/ * ---- ------------------------------------------------ -------------------------- --- * / / * Smooth Scroll / * Thanks for: https://github.com/davist11 / JQuery-One-Page-Nav / * ----------------- ----------------------- --------------------------- ---------------- * / $ (". Nav A pagename ({filter: ': (no .: (external)', changeHash: false, scrollSpeed: 1500,});} one page (); function smooth (scroll) (// scroll rsvp section $ ( ".js-scroll"). Animate ({action ()} {$ ('html, body'). Animate ({scrollTop: $ ("# rsvp") offset (). Top}, 2000); description is false;}); description is false; } SmoothScroll ();
})
jQuery (window) .load (function () {if (window.location.hash) {var Hash = window.location .hash.substring (1); if (jQuery ('a [href =' # '+ hash +'] ',' # menu-primary '). Length & gt; 0) {jQuery ('html, body'). ({ScrollTop: jQuery ("#" + hash) .offet (). Top}, 1000);}}
})
< DivX = "post-text" itemprop = "text">
To get the same functionality of working with the menu click, you can create jQuery events page load
or documents
, so when the page you are on, you can check the URL
in the URL
and trigger the menu with the same code href
:
jquery (document) .ready (function () {if (window.location.hash) {var hash = window.location.hash.substring (1); if (jQuery ('A [# * + hash +'] ',' # menu-p Primary '). Length & gt; 0) {jQuery (' a [href = "# '+ hash +'] ',' # menu-primary ') .trigger (' click ');}}});
Or you can try this to find the right element position and scroll to the same section:
jQuery. } {If (window.location.hash) {var hash = window.location.hash.substring (1); if (jQuery ('a [href = "#' + hash + ']', '# menu-primary' ) .length & gt; 0) {jQuery ('html, body'). Chetan ({scrollTop: jQuery ("#" + hash). Offset (). Top}, 1000);}}});
On window load:
jQuery (window) .load (function () {if (window.location.hash) {var hash = window Location .hash.substring (1); if (jQuery ('a [href =' # '+ hash +'] ',' # menu-primary '). Length> 0) {jQuery (' html, body ') Chetan ({scrollTop: jQuery ("#" + hash). Offset (). Top}, 1000);}}});
Comments
Post a Comment