title: Navbar animation doesn't stop on scroll event with velocity.js (works with jQuery)
body: <p>I have a fixed top navbar that should slide up when the user scrolls past a certain point and be replaced with a slimmer navbar. I'm using velocity.js to animate the switch with <code>.velocity("slideUp")</code> / <code>("slideDown")</code>. However, the animation doesn't stop looping. The switch works fine with jQuery <code>slideUp()</code> and <code>slideDown()</code> though.</p>
  
  <p><strong>Here's the velocity version:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var offsetPos = $( "h1" ).offset().top;
  var navFull = $( ".navbar-full" );
  var navShrink = $( ".navbar-shrink" );
  
  navShrink.hide();
  
  function navChange() {
    var scrollPos = $( this ).scrollTop();
    
    if ( scrollPos &gt; offsetPos ) {
  
      navFull.velocity("slideUp");
      navShrink.velocity("slideDown");
  
    } else {
  
      navFull.velocity("slideDown");
      navShrink.velocity("slideUp");
    }
  }
  $( window ).on( "scroll", navChange );  </code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>html, body {
    position: relative;
    margin: 0;
  }
  .content {
    width: 600px;
    margin: 0 auto;
    position: relative;
  }
  nav {
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1;
  }
  nav p {
    text-align: center;
  }
  .content h1 {
    margin-top: 150px;
  }
  .navbar-full {
    height: 100px;
    background: blue;
  }
  .navbar-shrink {
    height: 50px;
    background: red;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/velocity/1.2.3/velocity.js"&gt;&lt;/script&gt;
  &lt;nav class="navbar-full"&gt;
    &lt;p&gt;Why doesn't this stop!&lt;/p&gt;
   &lt;/nav&gt;
  &lt;nav class="navbar-shrink"&gt;
    &lt;p&gt;Why doesn't this stop!&lt;/p&gt;
   &lt;/nav&gt;
  &lt;div class="content"&gt;
    &lt;h1&gt;Content&lt;/h1&gt;
    &lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod ducimus quia sed, iusto alias temporibus perspiciatis placeat omnis cupiditate laborum ex neque excepturi, ipsum. Quibusdam deleniti porro, assumenda possimus deserunt maiores ipsam non fuga est, voluptatem. Placeat beatae voluptatibus dolores id quis, sit ipsum vitae ducimus ab ipsam eos qui tempo Lorem ipsum dolor sit amet, consectetur adipisicing elit. Consectetur dolorum maxime hic eaque mollitia autem laboriosam eveniet dolores voluptates, nisi quos minus voluptate est placeat maiores earum assumenda ducimus laudantium. Labore obcaecati ipsum, molestiae harum, ex tenetur enim, aut asperiot consequuntur magnam magni. Eaque quidem explicabo tempora, cum numquam sint totam corporis sunt, deleniti illum perspiciatis molestiasam numquam deserunt optio molestiae deleniti maiores molestias! Beatae et non fuga consequatur ea quisquam, iusto minima cum eligendi. Molestiae possimus ipsa pariatur facilis at. Repudiandae inventore quod quis neque cumque, tenetur, cum. Numquam quas illum nihils veniam rem fuga, fugit nesciunt asperiores at facilis ut amet, quo! Laudantium consequatur quis, incidunt accusantium assumenda harum velit, saepe molestias omnis eveniet iste vel ea, eaque. Magnam porro eligendi quasi aspernatur. Numquam quis, eius?Lorem ipsum dolor sit amet, consectetur adipisicing elit. Nobis voluptas, labore odio. Laboriosam fugit voluptate velit. Cupiditate fugit optio illum porro deserunt qui, eius corrupti, quod quia rerum, molestiae nostrum asperiores voluptates fuga animi perferendis. Perspiciatis nulla exercitationem quis aliquam fugit minus unde architecto vero nostrum quos, repellendus delectus aperiam porro, voluptatum accusamus eius. Facilis dolores culpa aliquid temporibus, inventore ad quisquam numquam, eum voluptas, harum consequuntur est deleniti! Sit odio repudiandae tempore tempora, ut eum nam rem error ipsum enim maxime fugit, laudantium quidem labore aliquam eligendi est magnam? Obcaecati qui cupiditate cum quis soluta ut quod consequuntur, iste impedit, placeat cumque excepturi optio, eligendi vel. Cupiditate ut ducimus perferendis, delectus molestias doloremque laboriosam praesentium aut nostrum reprehenderit nihil ea quam quos eligendi dignissimos cumque nulla! Quae, voluptas eius totam veniam nulla minus itaque cupiditate incidunt rem temporibus debitis suscipit iusto nemo molestiae dolorum magni excepturi minima officiis inventore repellat. Porro non cumque adipisci iusto, molestias ipsum error. Perferendis labore est, ab similique, corporis eaque facilis aliquid dolore. Deleniti ut nesciunt optio distinctio vitae placeat ipsa officiis, temporibus nemo perspiciatis magnam. Quaerat voluptatibus minus dolore iure, perspiciatis similique saepe sint at, nulla, minima voluptate commodi? Deleniti, quos mollitia fuga.&lt;/p&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p><strong>And here it is working with jQuery:</strong></p>
  
  <p><a href="http://codepen.io/eAgobe/pen/OygXBR" rel="nofollow">CodePen</a></p>
  
  <p>I've tried the <code>stop()</code> and <code>stop(true,true)</code> trick to no avail...</p>
  
  <p>[Realise I didn't ask a question!]
  So, my question is: Why does this work in jQuery and not Velocity? Is there a way to make the event fire only once, specifically, at the scroll position? - as it looks like it fires on all scroll events.</p>
  
  <p>A caveat: I'm only a couple of months in to jQuery...</p>