2013-06-12 223 views
0

我想要的是讓鏈接帶我滾動動畫的下一步,而不移動整個身體,但只是我的「盒子」股利。滾動div div jquery

這裏是我的代碼:

<!DOCTYPE html> 
<html> 
<head> 
<title>Title of the document</title> 
<style> 
.out{background:gray;height:300px;} 
.box{height:300px;overflow:auto;} 
.question1{background:red;height:300px;} 
.question2{background:green;height:300px;} 
</style> 
</head> 

<body> 
<div class="out"> 
    here 
</div> 
<div class="box"> 
    <div class="question1" id="step1"> 
     step 1<br> 
     <a href="#step2">Step 2</a> 
    </div> 
    <div class="question2" id="step2"> 
     step 2 
    </div> 
</div> 
<div class="out"> 
    here 
</div> 
</body> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
<script> 
$(document).ready(function(){ 

    $('a[href^="#"]').click(function(){ 
     var the_id = $(this).attr("href"); 
     $('html, body').animate({ 
      scrollTop:$(the_id).offset().top 
     }, 'slow'); 
     return false; 
    }); 

}); 
</script> 
</html> 

回答

1

變化

$('html, body').animate({ 

$('.box').animate({ 
+0

哇人是正確的在我的面前。沒有看到即將到來!非常感謝你! – novoa