使用与<a href="#something"></a>类似的动画滚动到div的顶部

时间:2012-12-16 12:23:39

标签: jquery css jquery-animate

$(document).ready(function() {
    $('.up img').on('click', function(){
        $('.content').animate({top: '0'}, 1500, 'swing');
    })
});

这并没有激发我的内容,让我感到很困惑......

1 个答案:

答案 0 :(得分:2)

元素是否设置了top属性? 你可以使用scrollTop()

获得元素位置
$('html, body').animate({scrollTop:$('#SOMETHING').offset().top - 20},1500, 'swing');

将SOMETHING id替换为您要滚动到的元素