admin管理员组文章数量:1352795
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.
本文标签: javascriptUsing jQuerySmoothScroll from one page to anotherStack Overflow
版权声明:本文标题:javascript - Using jQuery-Smooth-Scroll from one page to another? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743920307a2561964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论