当我点击第一个点击我按钮时,它跳过第二个div并直接进入第三个div - 有谁知道这是为什么?我认为这可能是由于scrollTop函数可能?我希望第一次点击我带我到第二个div,第二个点击我按钮带我到第三个div。jQuery滚动跳过div
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div class="first">
<h1>My Home Screen</h1>
<button type="button">Click Me!</button>
<script>
$("button").click(function() {
$('html,body').animate({
scrollTop: $(".second").offset().top},
'slow');
});
</script>
</div>
<div class="second">
<button type="button">Click Me!</button>
<script>
$("button").click(function() {
$('html,body').animate({
scrollTop: $(".third").offset().top},
'slow');
});
</script>
</div>
<div class="third">
</div>
</body>
</html>
CSS:
h1 {
font-size: 12em;
margin-top:0;
text-align:center;
font-weight: bold;
color: white;
font-family: 'Century Gothic', CenturyGothic, AppleGothic, sans-serif;
text-shadow: 2px 2px 4px #000000;
}
.first {
width: auto;
height: 100vh;
background-image: url('home_screen.jpg');
background-repeat: no-repeat;
background-attachment:fixed;
background-size: cover;
}
.second {
width: auto;
height: 100vh;
background-image: url('second_screen.jpg');
background-repeat: no-repeat;
background-attachment:fixed;
background-size: cover;
}
.third {
width: auto;
height: 100vh;
background-image: url('third_screen.jpg');
background-repeat: no-repeat;
background-attachment:fixed;
background-size: cover;
}