user3653087
user3653087

Reputation: 70

jQuery: How to animate this scrollTop?

$("#wrapper").scrollTop($("#wrapper").scrollTop()+$("div.element.active").position().top);    
})

http://jsfiddle.net/yuFk5/250/

This script includes a workaround to allow scrolling with overflow hidden, but I am getting confused about how to implement animate into this to give the animation a duration.

Upvotes: 0

Views: 251

Answers (1)

Blake Plumb
Blake Plumb

Reputation: 7199

Based off the code in your jsFiddle

$( document ).ready(function() {
    $("#foo").click(function() {
        $("#wrapper").animate({'scrollTop': $("#wrapper").scrollTop()+$("div.element.active").position().top}, 400);    
    })
});

Upvotes: 3

Related Questions