从文档高度更改为特定ID

时间:2014-04-29 01:27:11

标签: jquery ajax scroll

我有这段代码,我想通常向下滚动到#results的页面底部

<script type="text/javascript">
$(function(){
    $('button[type=submit]').click(function(e){
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: "postpicks.php",
            data: $("#myform").serialize(),
            beforeSend: function(){
                $('#result').html('<div class="success"><img src="../images/loading-blue.gif" width="25" /></div>');
            },
            success: function(data){
                $('#result').html(data);
                $('html, body').animate({scrollTop:$(document).height()}, 'slow'); <---
            }
        });
    });
});

我喜欢滚动到#result的底部。

1 个答案:

答案 0 :(得分:0)

尝试使用:

$('html, body').animate({scrollTop:$('#result').offset().top}, 'slow');
相关问题