Reputation: 372
Is there a way to automatically scroll the box with the last child of class ask with jquery (animation: slow), the 3 ask
should stick to the top of the div box
?
<!DOCTYPE html>
<html>
<body>
<div id=box style="height: 200px; overflow-y: scroll;">
<span class=ask>1 ask<br><br><br><br><br><br><br></span>
<span class=reply>2 reply<br><br><br><br><br><br><br></span>
<span class=ask>3 ask<br><br><br><br><br><br><br></span>
<span class=reply>4 reply<br><br><br><br><br><br><br></span>
</body>
</html>
LIKE THIS:
Upvotes: 0
Views: 3452
Reputation: 1874
I think you might need smooth scrolling on last span
of answer of @kitanga Nday
$("span").last()[0].scrollIntoView({ behavior: 'smooth' });
Upvotes: 0
Reputation: 3565
You can use the scrollIntoView()
function. To use this with jQuery you do the following $(selector).last()[0].scrollIntoView()
and the element will be scrolled into view.
You can couple this with the css scrollbehaviour property and the browser will create an auto scroll effect for you without any setup. Do be warned that this css property isn't well supported
Upvotes: 4