title: How to add class after scrolling past anchor?
body: <p>I've built a page of accordion tabs.  Once the tab is opened the page auto scrolls to put the accordion panel header at the top of the page.  What I want to happen is when the user begins to scroll down a class is added to the panel header which shrinks it and makes it fixed to the top.  I've placed an anchor div just inside the body of the panel, however my script isn't activating.</p>
  
  <p>JS:</p>
  
  <pre><code>function sticky_relocate() {
        var window_top = $(window).scrollTop();
        var div_top = $('.shrink-anchor').offset().top;
        if (window_top &gt; div_top)
          $('.panel-heading a').addClass('shrink')
        else
          $('.panel-heading a').removeClass('shrink');
        }
       $(function() {
        $(window).scroll(sticky_relocate);
        sticky_relocate();
        });
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;div class="panel panel-main {{ id }}-panel"&gt;
      &lt;div class="panel-heading"&gt;
          &lt;h2 class="panel-title"&gt;
              &lt;a data-toggle="collapse" data-parent="#accordion" href="#{{ id }}"&gt;{% block icon %}&lt;span class="icon icon-cotm"&gt;&lt;/span&gt;{% endblock %} {% block title %}{% endblock %}&lt;/a&gt;
          &lt;/h2&gt;
      &lt;/div&gt;
      &lt;div id="{{ id }}" class="panel-collapse collapse"&gt;
          &lt;div class="panel-body"&gt;
              &lt;div class="shrink-anchor"&gt;&lt;/div&gt;
              {% block content %}
              {% endblock %}
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  
  
  <p>If I move the anchor div just inside the closing tag of the Header panel it sort of functions. The class is added, however very inconsistently. The top panels activate late. The middle panels activate on time. The lower panels activate too early.</p>
  
  <p>Took me awhile but put together a <a href="http://jsfiddle.net/6c1pra04" rel="nofollow">JSFIDDLE</a> to show you the issue. This doesn't have the auto scroll, but you can see the activations are off. It appears it is reading the anchor of collapsed panel 1.</p>