On Page Load Change To Anchor
I'm using Jquery.Localscroll to move the window smoothly between anchors. How would you change the URL when the page loads to include an anchor link so it scrolls smoothly to a sec
Solution 1:
Obviously if you specify the anchor to scroll to in the tradional way:
<ahref="yourURL#someanchor">Link</a>
Then the browser will scroll automatically.
If your intention is for the browser to load the page and then have your code kick in to do a smooth (animated) scroll to a particular anchor then something like this would work:
// on calling page
<a href="yourURL?scrollto=someanchor">Link</a>
// on "yourURL" page:
$(document).ready(function() {
// check for "scrollto" parameter and if it exists// use Localscroll to move to specified anchorvar match = /[?&]scrollto(?:=([^&]*))?/.exec(window.location.search);
if( match != null ){
var anchor = match[1];
// your code to scroll to anchor here
}
});
Post a Comment for "On Page Load Change To Anchor"