I'm currently coding a PHP and MYSQL chat. The chat messages are held in a div with the class '.chat'. It has a overflow:auto css element so it has a vertical scrollbar. I would like it so when you join the chat, it starts the scrollbar at the bottom.
I currently have the following code so far:
$(".chat").animate({ scrollTop: '7807897px' }, "fast");
This method doesn't always work, and can really become annoying. I know there must be an easier way out there, I'm just new to javascript and would really love some help :)
Thanks a lot
EDIT: My .chat div has a 80% height element. So the scroll by height doesn't seem to work for me
Why not get the height of .chat ?
$(".chat").animate({
scrollTop: $('.chat').height()
}, "fast");
If your scrolling the page you can use
$(document).height();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With