Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't need <code>Math.abs()</code> because <code>tpxl</code> will always be a positive number. To set the position of the div to be 100px from the current top of the window, use <code>$(window).scrollTop() + 100 + 'px'</code>.</p> <p>I don't really understand why you have the <code>if</code> / <code>else if</code> structure. The following would keep the div fixed at 100px all the time:</p> <pre><code>$(window).scroll(function () { $('#div').css('top', $(window).scrollTop() + 100 + 'px'); }).scroll(); </code></pre> <p>Demo: <a href="http://jsfiddle.net/G5BVU/" rel="nofollow">http://jsfiddle.net/G5BVU/</a></p> <p>To only set the position "fixed" when the scroll point is less than 100 or more than 700 like for your original code try this:</p> <pre><code>$(window).scroll(function () { var tpxl = $(window).scrollTop(); if (tpxl &lt; 100 || tpxl &gt; 700) { $('#div').css('top', tpxl + 100 + 'px'); } }).scroll(); </code></pre> <p>Demo: <a href="http://jsfiddle.net/G5BVU/1/" rel="nofollow">http://jsfiddle.net/G5BVU/1/</a></p> <p>EDIT: To have the element scroll normally except when the window is scrolled between those two points just reverse the <code>if</code> condition from my previous example:</p> <pre><code>if (tpxl &gt; 100 &amp;&amp; tpxl &lt; 700) $('#div').css('top', tpxl + 100 + 'px'); </code></pre> <p><a href="http://jsfiddle.net/G5BVU/2/" rel="nofollow">http://jsfiddle.net/G5BVU/2/</a></p> <p>In all cases provide an initial <code>top</code> setting as appropriate.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload