admin管理员组文章数量:1289633
When the user clicks a button, I want his browser to automatically scroll to an <a>
with a certain href (let's call it "abc"). Ideally the scrolling would be nicely animated in some way.
When the user clicks a button, I want his browser to automatically scroll to an <a>
with a certain href (let's call it "abc"). Ideally the scrolling would be nicely animated in some way.
- 1 Animations are distracting and get in the way of using the app. Unless your app is an animation tool of some kind. – tsilb Commented Sep 9, 2009 at 7:05
- What if the element he's scrolling to isn't visible without scrolling? A ScrollTo is good UX in that case. – Dave Ward Commented Jul 3, 2010 at 1:40
3 Answers
Reset to default 5Give a look to the jQuery.scrollTo plugin.
With that plugin you could simply:
$.scrollTo('a[href=abc]');
Way simpler:
element_to_scroll_to = document.getElementById('anchorName2');
element_to_scroll_to.scrollIntoView();
Even no need for jQuery ;)
You don't need any plugin.
$(document.documentElement).animate({
scrollTop: $('a#abc').offset().top
});
本文标签: javascriptScroll the page to an ltagt with a particular href with jQueryStack Overflow
版权声明:本文标题:javascript - Scroll the page to an <a> with a particular href with jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741445730a2379186.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论