当单击 .paging-navigation a
时,我试图让页面滚动到 #news .section-wrap
。我尝试插入该行(如下所示)但无法使其工作。我哪里出错了?
$('#article-list').on('click', '.paging-navigation a', function(e){
e.preventDefault();
var link = $(this).attr('href');
$('#article-list').scrollTo('#news .section-wrap'); // this is the line I added
$('#article-list').fadeOut(500, function(){
$(this).load(link + ' #article-list', function() {
$(this).find('#article-list > *').unwrap().end().fadeIn(500);
});
});
});
最佳答案
您需要对 html
和 body
进行动画处理,并指向 jQuery animate
函数中的选择器。试试这个:
$('html, body').animate({
scrollTop: $('#news .section-wrap').offset().top
}, 2000);
关于javascript - 单击按钮后滚动到 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25799121/