I am a firm believer that every day you should learn something new. In this particular case, I learned something new quite some time ago and just never applied it to my code samples. This is something I really want to pay more attention to because I do not want be a purveyor of misinformation.
Nick commented on this original post that once the animation began he could not scroll back up to the top of the post. Looking into the problem I immediately noticed what was happening, the scrollHeight attribute was not taking into account the height of the scrolling div. If the scrolling div has a height of 100px initially and enough text has been entered to scroll it, it may have a scrollHeight of 120px. Moving down to the bottom of the div, the scrollTop would be 20px which is the scrollHeight – $(‘#div’).height(). Adjusting for that in the jQuery code will make it function as expected.
The corrected code is below:
As JP points out in the comments below, this may need to be modified to work with jQuery 1.6.1