title: how to move div up & down on window scroll
body: <p>I have a jquery function to move some div up and down while scrolling the page here is the code -></p>
  
  <pre><code>$(window).scroll(function() {
    $(".mydiv").css({
      "margin-top": ($(window).scrollTop()) + "px",
      "margin-left": ($(window).scrollLeft()) + "px"
    });
  });
  </code></pre>
  
  <p>This above code only works on one div like -></p>
  
  <pre><code>&lt;div class="mydiv"&gt;This div works&lt;/div&gt;
  &lt;div class="mydiv"&gt;This div takes a high distance from above div and goes down&lt;/div&gt;
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(window).scroll(function() {
    $(".mydiv").css({
      "margin-top": ($(window).scrollTop()) + "px",
      "margin-left": ($(window).scrollLeft()) + "px"
    });
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>body {
    height: 1000px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;div class="mydiv"&gt;This div works&lt;/div&gt;
  &lt;div class="mydiv"&gt;This div takes a high distance from above div and goes down&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>