动画滚动到 div 内的散列不起作用

Animate scroll to hash inside div not working

为什么只有当滚动是页面本身而不是 div 时才有效?我确实只是在没有动画的情况下移动到正确的位置。

$(document).ready(function(){

  $('a[href^="#"]').on('click',function (e) {
    e.preventDefault();

    var target = this.hash;
    var $target = $(target);

    $('html, body').stop().animate({
      'scrollTop': $target.offset().top
    }, 5000, function () {
      window.location.hash = target;
    });
  });
});

http://codepen.io/ilyador/pen/OPpWKd

将动画更改为换行 class 喜欢你笔的这次更新 >> codePen << 更改为

 $('.wrap').stop().animate({