1

所以我有這種模式,當你點擊計算按鈕時,我想自動向下滾動到圖表區域。我有這樣的代碼: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

回答

0

我不知道這是否會解決你的問題,但這裏是一個小提琴 - 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>