私にはすべてがうまくいくようです。特定の要素にスクロールするための最も関連性の高いコードは次のとおりです。
$('html, body').animate({ scrollTop: $('#box').offset().top }, 2000);
必要に応じてピクセルを追加して、完全に配置することができます。
$('html, body').animate({ scrollTop: $('#box').offset().top + 10 }, 2000);
私はあなたのhttp://jsbin.com/ewulum/2/editに入り、いくつかの変更を加えました:
.wrapper {
width: 90%;
margin: 0 auto;
background:#ececec;
overflow: auto;
height: 250px;
}
JS ファイル
//event delegation
$("#nav-wrapper").on("click", "a", function(e){
var cur_el_href = $(this).attr("href"),
cur_el_top =$(cur_el_href).offset().top;
e.preventDefault();
console.log("The current elem's href value is " + cur_el_href);
console.log("The target section's offset top is " + cur_el_top);
$(".wrapper").animate({
scrollTop:cur_el_top
},
800, function(){
//this callback is for demonstration only so as not to back to top when testing other links
$(this).animate({scrollTop:0}, 1000);
});
});