jQuery How to .scrollTo() inside .scroll() on if() statement?
<p>How do I use <code>.scrollTo()</code> with an <code>if()</code> statement inside the <code>.scroll()</code> handler?</p>

<p>Here's my code so far:</p>

<pre><code>scrollToPage = function() {
    $(document).scrollTo($('.page'), 750, { easing: 'easeInOutCubic' });
}

$(window).scroll(function() {
    if ($(this).scrollTop() &gt;= ($(this).height()-107)) {
        $('.page').addClass('page-top');
        $('header').css({position: 'fixed'});
    }
    else {
        scrollToPage();      //  This part doesn't work
    }
});
</code></pre>

<p>So basically, <code>if</code> the scrolling reaches a certain point (windowHeight-107), the actual content-page is at the top of the window, and the header will get positioned fixed.</p>

<p>But <code>else</code> (when the content-page is not at the top), I want it to scroll automatically to it.</p>

<p>However, it tries to scroll to it again after this first time, everytime I want to scroll further or back. It seems to get stuck.</p>

<p>What's exactly happening here, and how do I get around this?</p>

<p>Anyone?</p>
