Scroll Bootstrap 3 modal

问题描述:

所以我有这种模式,当你点击计算按钮时,我想自动向下滚动到图表区域。我有这样的代码:Scroll Bootstrap 3 modal

$('#budgetCalModal').animate({ 
    scrollTop: $("#result").offset().top 
    }, 1000); 

但它似乎没有工作。我使用bootstrap 3.任何线索? PS:当模态明显大于窗口高度时,它应该滚动。

感谢

enter image description here

+3

请显示您的html和js代码有问题。而且最好也用你的问题创建一个bootply。 – Sebsemillia 2014-09-03 17:34:04

我不知道这是否会解决你的问题,但这里是一个小提琴 - http://jsfiddle.net/qe1w87ba/已经做了你基于模态窗口内的锚标记想要的东西。

<script> 
$(function() { 
    $('a[href*=#]:not([href=#])').click(function() { 
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { 

     var target = $(this.hash); 
     target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); 
     if (target.length) { 
     $('.modal').animate({ 
      scrollTop: target.offset().top 
     }, 1000); 
     return false; 
     } 
    } 
    }); 
}); 
</script>