I have an accordion that opens and closes open clicking. The problem I have is that I want the page to scroll to the top of div when it's clicked on. What I have doesn't quite work, it scrolls to where the top of div was when clicked on, not where it is. My jQuery code is:
$(".aro > .wrap").click(function () {
if (!$(this).parent().hasClass("active")) {
$(".active .details").slideUp("slow");
$(".aro").removeClass("active");
$(this).parent().addClass("active");
$(this).parent().children(".details").slideDown("slow");
}
else {
$(this).parent().removeClass("active");
$(this).parent().children(".details").slideUp("slow");
}
$('html, body').animate({
scrollTop: $(this).offset().top
}, 2000);
});
I made a simple JSFiddle at: http://jsfiddle.net/489Y2/1/
Anyone know what I'm doing wrong?