为什么这仅在滚动是页面本身而不是在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
将
动画更改为包装类,就像这次笔的更新一样>>代码笔<<改为
$('.wrap').stop().animate({