【发布时间】:2017-12-09 15:05:49
【问题描述】:
我有几个类名为“fullcontent”的 div。 在每个 div 中,我有 2 个元素:“fullcontent--prev”和“fullcontent--next”。 单击此元素时,我想滚动到下一个/上一个 fullcontent-div。
但我不明白这个:
https://jsfiddle.net/whgxauyd/1/
$(".fullcontent--prev").click(function() {
$('html, body').animate({
scrollTop: $('.fullcontent').nextAll().offset().top
}, 1000, 'easeInOutSine');
});
$(".fullcontent--next").click(function() {
$('html, body').animate({
scrollTop: $('.fullcontent').nextAll().offset().top
}, 1000, 'easeInOutSine');
});
.fullcontent {
z-index: 900;
width: 100%;
height: 100vh;
opacity: 0.5;
font-size: 60px;
color: black;
position: relative;
background-color: yellow;
margin-bottom: 100px;
&--prev {
height: 25%;
width: 100%;
top: 0;
left: 0;
opacity: 0.5;
position: absolute;
background-color: red;
cursor: pointer;
}
&--next {
height: 75%;
width: 100%;
bottom: 0;
left: 0;
opacity: 0.55;
position: absolute;
background-color: green;
cursor: pointer;
}
}
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<section>
<div class="fullcontent"> 1
<div class="fullcontent--prev"></div>
<div class="fullcontent--next"></div>
</div>
<div class="fullcontent"> 2
<div class="fullcontent--prev"></div>
<div class="fullcontent--next"></div>
</div>
<div class="fullcontent"> 3
<div class="fullcontent--prev"></div>
<div class="fullcontent--next"></div>
</div>
<div class="fullcontent"> 4
<div class="fullcontent--prev"></div>
<div class="fullcontent--next"></div>
</div>
</section>
哪里出错了?
【问题讨论】: