我用ajax加载一个页面,我想让主页自动滚动到加载页面的开头。下面是我使用的代码:
html
<button class="btn btn-info btn-lg" type="button" id="photos"> <i class="fa fa-plus fa-5x"></i><br>Add Photo</button>在页面的底部,我有这个js代码
$(document).ready(function(){
$("#photos").click(function(){
$(".content-loader").fadeOut('slow', function()
{
$(".content-loader").fadeIn('slow');
$(".content-loader").load('somepage.php?pid=3');
});
});上面的代码运行良好,页面'somepage.php?pid=3‘已加载到<div class="content-loader">中。当页面'somepage.php?pid=3‘被加载时,如何让页面自动滚动到<div class="content-loader">?
发布于 2017-07-21 23:19:00
下面的代码应该适用于.load()函数。它应该在load complete上滚动
$(".content-loader").load('somepage.php?pid=3', function () {
$('html,body').animate({scrollTop: $(".content-loader").offset().top});
});https://stackoverflow.com/questions/45241136
复制相似问题