title: jQuery make div slide in when scrolling down page
body: <p>I want to make a div slide onto my page from the right when a user scrolls down the page (the div will contain a link that takes them back to the top of the page). Here is the code I'm currently using:</p>
  
  <pre><code>jQuery(window).scroll(function() {
  if (jQuery(this).scrollTop() &gt; 100) {
      jQuery('.totop').animate({ right: '0px' });
  } else {
      jQuery('.totop').animate({ right: '-300px' });
  }
  });
  </code></pre>
  
  <p>And the CSS:</p>
  
  <pre><code>.totop {
  position:fixed;
  bottom:50%;
  right:-300px;
  width:300px;
  height:100px;
  font-size:30px;
  color:white;
  background:#f18500;
  }
  </code></pre>
  
  <p>The Div is behaving very oddly, when I scroll down the div takes about 5 seconds to appear, then it comes into view but looks like it is making several attempts to slide off again before remaining still, when I slide back to the top it dissapears...but after about 5 seconds again. Would love some help to find out what is wrong with my code please.</p>