2013-06-12 172 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