I’m making a custom scrollTo() function.
My function is:
function scrollTo(wait, scroll, time) {
if (scroll == 'top' || scroll == 'Top') {
if (wait == 0) {
wait = 1;
}
$('html, body').delay(wait).animate({
scrollTop: 0
}, time);
}
else if (scroll === 'bottom' || scroll == 'Bottom') {
time = time + 6000;
$('html, body').delay(wait).animate({
scrollTop: 60000
}, time);
}
else {
$('html, body').delay(wait).animate({
scrollTop: scroll
}, time);
}
}
With an HTML that I just used really quick:
<div onclick="scrollTo(0, 'Bottom', 1500);">To Bottom</div>
<br><br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>
br<br>br<br>br<br>br<br>br<br>
br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br
<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>
<br><br><br><br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>
br<br>br<br>br<br>br<br>br<br>
br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br
<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>br<br>
<br><br>
<div onclick="scrollTo(0, 'Top', 1500);">Top</div>
Problem:
When I click To Bottom it scrolls down fine, but then when I click Top it delays really long before going up. I don’t know why though.
Any Solutions?
Thanks.
You already have the answer, but I would like to ask you to slightly modify code, so I could sleep peacefully.