I am quite new to jQuery and I cannot get the following code to work. I want to animate the scrolling of a certain paragraph within a div to the top, but somehow the animation fails to run.
Please find the code in this fiddle:
$(document).ready(function(){
$('#div1').scroll(function() {
var par1toTop = $('#par1').position().top;
if ($('#div1').scrollTop() >= par1toTop) {
var par5toTop = $('#par5').position().top;
if ($('#div2').scrollTop() != par5toTop && par5toTop != 0) {
//why can't I animate the scrolling here?
$('#div2').animate({scrollTop(par5toTop)}, 800);
}
}
});
});