.offset返回null的属性

时间:2014-02-06 18:04:36

标签: jquery

不确定为什么每当我点击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">&mdash; Technology &mdash;</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;
})

0 个答案:

没有答案