I am trying to implement a function where the .hidden
class is added to a div only when it has scrolled to the top. I know I can use SetTimeout
, but I want to ensure that the div disappears only when it has reached the top of the scroll.
$(".more").on("click", function() {
$("#wait").animate({
scrollTop: 0
}),
$(".more").toggleClass("nascosto"),
$("#wait").toggleClass("hidden")
});
.more {
cursor: pointer;
position: fixed;
font-size: 30px;
top: 10px;
left: 10px;
}
#wait {
font-size: 30px;
right: 10px;
width: 50%;
position: fixed;
overflow-y: scroll;
height: 100vh;
}
#about {
overflow-y: scroll;
}
.hidden {
opacity: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class=more>click</div>
<div id="wait">
<div id=about
">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div></div>