title: Stop flickering when dynamically fixing div
body: <p>I fix a div to the bottom of the window once it's position is scrolled out of window view. I then 'unfix' it when it's postion is scrolled back into view. If the scrolling is done slowly there is a horrible flickering of postions. Is there a way of combating this?</p>
  
  <p>DEMO <a href="https://jsfiddle.net/3146nxLx/" rel="nofollow">https://jsfiddle.net/3146nxLx/</a></p>
  
  <pre><code>var initSet = false;
  $(window).scroll(function() {
    if (isScrolledIntoView($('#myDivTrigger'))) {
      if (!initSet) {
        initSet = true;
      }
      $("#myDiv").removeClass('fixed');
    } else if (initSet) {
      $("#myDiv").addClass('fixed');
    }
  });
  
  function isScrolledIntoView(elem) {
    var $elem = $(elem);
    var $window = $(window);
  
    var docViewTop = $window.scrollTop();
    var docViewBottom = docViewTop + $window.height();
  
    var elemTop = $elem.offset().top;
    var elemBottom = elemTop + $elem.height();
  
    return ((elemBottom &lt;= docViewBottom) &amp;&amp; (elemTop &gt;= docViewTop));
  }
  </code></pre>