Jquery click to scroll

时间:2015-09-14 15:23:46

标签: javascript jquery

I'm trying to get it when the #name div is pressed, the page will scroll to #profile-pic but not having any luck.

$("#name").click(function() {
$('html, body').animate({
    scrollTop: $("#profile-pic").offset().top
}, 2000);
});

http://jsfiddle.net/qv9f7p6u/1/

1 个答案:

答案 0 :(得分:3)

Because the scrollable part is a div, not the page. You need to select the div to scroll.

$('#left-panel').animate({