滚动到div ajax/javascript [英] scroll to div ajax/javascript
本文介绍了滚动到div ajax/javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,对于我的一生,我无法使它正常工作.我搜索了示例,发现了很多吨.但是它们似乎都不适合我.
Ok, for the life of me, I can't get this to work. I've searched for examples and I found tons. But none of them seem to work for me.
问题很简单,我有一个div
,它从数据库中加载内容.
加载页面时,我需要滚动到div的底部.
这是一个例子.
Question is simple, I have a div
that loads content from the database.
I need to scroll to the bottom of the div when the page is loaded.
here's an example.
<body>
<div id="container">
<div id="messagewindow">
<?php
foreach($results as $r){
//content loop..
}
?>
<div id="scrolltome"></div>
</div>
</div>
</body>
我添加了div
id scrolltome
,希望它能起作用.
I added the div
id scrolltome
in hopes it would work.
提前谢谢!
推荐答案
在窗口加载时,只需将#scrolltome div的顶部偏移距离传递到主体scrollTop即可,如下所示:-
Simply pass the top offset distance of #scrolltome div to body scrollTop on window load like this:-
$(window).load(function(e) {
var distance = $('#scrolltome').offset().top
$('html,body').animate({scrollTop:distance},1500);
});
这篇关于滚动到div ajax/javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文