當我點擊第一個點擊我按鈕時,它跳過第二個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;
}