简体   繁体   English

添加动态内容后跳转到页面上的位置

[英]Jumping to Position on page after Dynamic content added

I use ajax to dynamically add content to my site but i want the page to jump to the content has been added but i cant get i to work. 我使用ajax将内容动态添加到我的网站,但是我希望页面跳转到已添加的内容,但是我无法让我工作。

here is the link i am using to add the content and to jump the the position. 这是我用来添加内容并跳转位置的链接。

<a href="javascript:ajaxpage('/console/new_message_profile.php', 'message_area');" onclick="window.scrollTo(0, 2000);">

Give an id to the dynamically generated element and then 为动态生成的元素指定一个id ,然后

$("#idofdynamicelement")[0].scrollIntoView( true );
// O to make sure its the first item if multiple found
// true to indicate the top position

It seems that you let the page scroll to its bottom by using window.scrollTo(0, 2000); 似乎您通过使用window.scrollTo(0,2000);将页面滚动到了其底部。 I have tried your code on my server,and it worked fine . 我已经在服务器上尝试了您的代码,但效果很好。 Can you give more details? 您能提供更多细节吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM