title: Sticky Nav flickering like flashing lights
body: <p>I wrote the code to make the nav to be a sticky nav, but the code that I wrote to make it a sticky nav is causing the sticky nav to blink, why? Where is the fault?</p>
  
  <p>Here is my code :</p>
  
  <pre><code>;(function($) {
  
      $.fn.tosticky = function(o) {
  
          o = $.extend({
  
              tofixedClass: 'classtofixed',
              fixedClass: 'fixedclass',
              top: 0,
              bottom: 0
  
          }, o);
  
          return this.each(function() {
  
              var $window = $(window),
                  $this = $(this);    
  
              $window.on("scroll", function() {
                  var fence = $(o.tofixedClass).offset().top;
                  var scrollTop = $(this).scrollTop();
                  if(scrollTop &gt; fence) {
                      $(o.tofixedClass).addClass(o.fixedClass).css({"margin-top":o.top,"margin-bottom":o.bottom});
                  } else {
                      $(o.tofixedClass).removeClass(o.fixedClass);
                  }  
              });
  
          });
      };
  })(jQuery);
  
  $(function () { 
      $(".pagar").tosticky({ // use this to run code in above
          tofixedClass: '.pagar',
          fixedClass: 'fixed',
          top: 0,
          bottom: 0 
      });
  });
  </code></pre>
  
  <p>And here is my code in jsfiddle : <a href="http://jsfiddle.net/bagusa4/1wxggpv5/4/" rel="nofollow noreferrer">Click Here</a></p>