I am currently using jQuery-Smooth-Scroll to smoothly scroll up and down to various anchor positions on one of my pages (Page 1). However, what I would also like to be able to do is, from another page (Page 2), link to Page1 (appending #bookmark to the url) and have jQuery-Smooth-Scroll pick up on the fact I am calling the page with a #bookmark and have it smoothly scroll down to the relevant position once the page has pleted loading. I don't know if this is a possibility or not?
This is the version of Smooth-Scroll that I'm using:
I'm still relatively new to jQuery so I may be overlooking something obvious.
I am currently using jQuery-Smooth-Scroll to smoothly scroll up and down to various anchor positions on one of my pages (Page 1). However, what I would also like to be able to do is, from another page (Page 2), link to Page1 (appending #bookmark to the url) and have jQuery-Smooth-Scroll pick up on the fact I am calling the page with a #bookmark and have it smoothly scroll down to the relevant position once the page has pleted loading. I don't know if this is a possibility or not?
This is the version of Smooth-Scroll that I'm using:
https://github./kswedberg/jquery-smooth-scroll
I'm still relatively new to jQuery so I may be overlooking something obvious.
Share Improve this question edited Jan 21, 2011 at 13:02 marcusstarnes asked Jan 21, 2011 at 9:04 marcusstarnesmarcusstarnes 6,53115 gold badges70 silver badges115 bronze badges2 Answers
Reset to default 7Ajma's answer should be sufficient, but for pleteness:
alert(location.hash)
Edit: a more plete example:
// on document.ready {
if (location.hash != '') {
var a = $("a[name=" + location.hash.substring(1) + "]");
// note that according to w3c specs, the url hash can also refer to the id
// of an element. if so, the above statement bees
// var a = $(location.hash);
if (a.length) {
$('html,body').animate({
scrollTop: $(a).offset().top
}, 'slow');
}
}
// }
It's possible, you want to put a call into the smooth scroll function when the page is finished loading. in jQuery, it's using $(document).ready(function () { your code } );
You'll need to put something in to parse your url to extract the #bookmark and then call the smooth scroll.