Federico Ferrari Federico Ferrari - 1 year ago 63
CSS Question

Run a function only when another one is finished

I have this function and I want to add

class only when the div had scroll to top. I know I can use
but it would be random and I want to be sure that the div disappear when had scroll to top.

$(".more").on("click", function() {
scrollTop: 0

.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>

Answer Source

If you refer to the jQuery documentation on .animate(), you will see that you can provide a complete function.


complete Type: Function() A function to call once the animation is complete, called once per matched element.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download