Hi I’m having trouble implenting an answer to a previous question
// 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 anchor
var match = /[?&]scrollto(?:=([^&]*))?/.exec(window.location.search);
if( match != null ){
var anchor = match[1];
// your code to scroll to anchor here
}
});
I wasn’t sure what the ‘code to scroll to anchor’ was in regards to .localscroll I have tried this and it doesn’t seem to work.
$(document).ready(function() {
// check for "scrollto" parameter and if it exists
// use Localscroll to move to specified anchor
var match = /[?&]scrollto(?:=([^&]*))?/.exec(window.location.search);
if( match != null ){
var anchor = match[1];
$.localScroll({
target: '#section3a', // could be a selector or a jQuery object too.
duration:1000,
hash:true,
onBefore:function( e, anchor, $target ){
// The 'this' is the settings object, can be modified
},
onAfter:function( anchor, settings ){
// The 'this' contains the scrolled element (#content)
}
});
}
});
If someone has used localscroll before could they please help me fire a function when the document loads so it scrolls to an #anchor
I have tried the scrollTo feature:
$(document).ready(function() {
$.scrollTo( '#section3a' , 1000) ;
});
Which works but it needs to be offset by the left -295 and the top-120
Ideally when the page loads I want to to scroll smoothly to another section. The introduction is in the middle of the long page.
Thanks for any help.
Found the offset. I feel very silly, sorry.