我正在尝试的是获取链接,带我滚动动画的下一步而不移动整个身体,只是我的“盒子”div。
这是我的代码:
<!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>
答案 0 :(得分:1)
更改
$('html, body').animate({
到
$('.box').animate({