jquery / javascript: Uncaught TypeError?
<p>hey guys,
i wrote a little custom animated scroll function...</p>

<pre><code>function scroll(selector, animate, viewOffset) {

    pageOffset = selector.offset();
    scrollPos = pageOffset.top - viewOffset;

    if (animate) {

        $('html, body').animate({scrollTop : scrollPos + 'px'}, {
            duration: 'slow', // how fast we are animating
            easing: 'easeOutQuint', // the type of easing
            complete: function() { }
        });

    } else {
        $('html, body').scrollTop( scrollPos );
    }

}
</code></pre>

<p>I call it with  <code>scroll($('#something'), false, 30);</code></p>

<p>It actually works, however sometimes it's a little bit buggy and the function doesn't properly work. I always call the scroll() function on a click-event.</p>

<p>The biggest problem I have is that on page load my console tells me the following line.</p>

<blockquote>
  <p>Uncaught TypeError: Cannot read
  property 'top' of null (script.js line 191 which is line 3 in my example above)</p>
</blockquote>

<p>Any idea what could cause this error? the scroll() function is not even called on dom-ready or on-load. It's just called on specific click-events.</p>

<p>thank you for your help</p>
