不确定为什么每当我点击Cannot read property 'top' of null
的A标记而不是滚动到它时,它都会返回.fullWidthBorder
。
NAV
<div class="fullWidthBorder">
<div class="row show-for-large-up">
<li class="technology">
<a data-scroll="technology">Technology <span class="navArrow"></span>
</a>
</li>
</div>
</div>
BODY
<div class="content-block">
<div class="responsive-container">
<h1 class="centered" data-scroll="technology" id="technology">— Technology —</h1>
<div class="clear"></div>
</div>
JAVASCRIPT
$('.fullWidthBorder a').on('click', function() {
var scrollAnchor = $(this).attr('data-scroll'),
scrollPoint = $('h1[data-anchor="' + scrollAnchor + '"]').offset().top - 28;
$('body,html').animate({
scrollTop: scrollPoint
}, 500);
return false;
})