在bootstrap模式中更改scrollTop()

时间:2016-01-18 12:18:41

标签: jquery twitter-bootstrap bootstrap-modal

在bootstrap模式中,当我在底部添加新表单时,我想将scrollTop()从其位置移动,即可能"0",移动到100px,当我点击ajax链接它显示一个表单,执行代码后显示我已经放置代码的表单:

$('html, body').animate({ scrollTop: 100 });

我认为它应该按照我的意愿完成它的工作,但事实并非如此。我还将代码作为函数scrollDown(n)放在父页面中,并在显示Ajax代码的表单之后调用该函数。但还是没有运气...... 我不知道我做错了什么?

任何帮助表示赞赏。感谢

编辑: 此代码显示模式中的电子邮件形式,实际上更改模态高度,我想将滚动条移动到apx:100px从顶部向下。 显示表单的代码是:

function showEmailBox(person_sno,fir_sno,divFrm){
    try{
        $("#"+divFrm).show();
        $("#"+divFrm).removeClass("animated rubberBand");
        $("#"+divFrm).load("../ajaxPhp/emailReminderForm.php",{person_sno:person_sno,fir_sno:fir_sno,divFrm:divFrm},function(txt,status,xhr){
            if(xhr.statusText == 'OK'){
                $(this).html(txt).addClass("animated rubberBand");
                }
            else{
                $(this).html('Error: - '+ xhr.status+' '+xhr.statusText).addClass('text-danger');
                }
            });             
        }catch(e){
            alert(e.message);
        }
        setTimeout(function(){
                $(this).removeClass("animated rubberBand");
                },500);
                $('html, body').animate({ scrollTop: 100 });
        }

这是最后一行

 $('html, body').animate({ scrollTop: 100 });

此行不起作用?

1 个答案:

答案 0 :(得分:2)

我找到了同样问题的解决方案。 你可以为此scrollTop 0px,

$('html, body').animate({scrollTop : '0px'}, 0);

希望这会对你有所帮助。