滚动到顶部Ajax内容加载后 [英] Scroll to top after Ajax content load
本文介绍了滚动到顶部Ajax内容加载后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
反正是有,我可以把它这样的页面会自动滚动到顶部后的内容有(通过Ajax)装?
Is there anyway that I can make it so the page will automatically scroll to the top after the content has loaded (via Ajax)?
这是在code我对显示内容:
This is the code I have for displaying the content:
$(document).ready(function () {
var my_layout = $('#container').layout();
$("a.item_link").click(function () {
$("#loader").fadeIn();
feed_url = $(this).attr("href");
$.ajax({
type: "POST",
data: "URL=" + feed_url,
url: "view.php",
success: function (msg) {
$("#view-area").html(msg);
$("#loader").fadeOut();
}
});
return false;
});
});
所以在视图区已加载的内容,我可以让页面自动滚动到顶部?
So after the 'view-area' has loaded its content can I make the page auto scroll to the top?
推荐答案
只需使用滚动功能
scrollTo(0);
如果你想了jQuery,然后这里是一个很好的例子与平滑:)
If you want the jquery, then here is a good example with smoothing :)
从链接:
$('html, body').animate({ scrollTop: 0 }, 0);
//nice and slow :)
$('html, body').animate({ scrollTop: 0 }, 'slow');
要放在你的code
...
success: function (msg) {
$("#view-area").html(msg);
$("#loader").fadeOut();
//Put code here like so
$('html, body').animate({ scrollTop: 0 }, 0);
}
这篇关于滚动到顶部Ajax内容加载后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文