admin管理员组文章数量:1429086
Say the user is viewing a particular part of the page, when behind the scenes an auto update feature runs, and right above or below the user's screen some more content is added.
I have the id of the newly added content's div.
How can I smoothly scroll the user to the newly added div using jquery or plain javascript? Must work in all major browsers.
Say the user is viewing a particular part of the page, when behind the scenes an auto update feature runs, and right above or below the user's screen some more content is added.
I have the id of the newly added content's div.
How can I smoothly scroll the user to the newly added div using jquery or plain javascript? Must work in all major browsers.
Share Improve this question asked Jun 6, 2012 at 14:03 AliAli 268k269 gold badges592 silver badges786 bronze badges3 Answers
Reset to default 7Here's what I use for jQuery
$('html,body').animate({scrollTop: jQuery("#ID").offset().top},'slow');
I think, this should work...with jquery.
$(window).scroll($('#newly-added-elem').offset().top);
UPDATE: smooth scrolling can be achieved with this:
$('body').animate({scrollTop: $('#newly-added-elem').offset().top},'slow');
Use an anchor:
<a name="newelement">.... new element stuff here ...</a>
then change the page's URL to point at that new element:
http://example./yourpage.html#newelement
本文标签: javascriptHow to scroll to a newly added dom elementStack Overflow
版权声明:本文标题:javascript - How to scroll to a newly added dom element? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745540190a2662457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论