In order to replicate the issue I am experiencing, please click on the down
button four times, and then click on the up
button. You will observe that you need to click the up button one extra time for it to function properly. How can I detect when it has reached the bottom and return false?
var scrollValue = 0;
$('#down').click(function(){
scrollValue = scrollValue + 180;
$('ul').animate({scrollTop:scrollValue});
});
$('#up').click(function(){
scrollValue = scrollValue + -180;
$('ul').animate({scrollTop:scrollValue});
});
ul {
padding: 0;
margin: 0;
height: 180px;
overflow: auto;
}
li {
height: 50px;
background: pink;
list-style: none;
margin-bottom: 10px;
height: 50px;
}
body {
padding: 0;
margin: 0;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
<button id="up">up</button>
<button id="down">down</button>