Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Firstly, change your CSS to the follow:</p> <pre><code>.holder span.top{ display:block; z-index:999; right:0; float:right; } </code></pre> <p>If you noticed, I removed <code>position:absolute</code> and <code>top:0</code> from the above declarations. This is done so that the element is still residing within the flow of the document and will not go beyond it's parent. In order to make it go to the extreme right, I simply added <code>float:right</code>.</p> <p>Next, change your jQuery to this:</p> <pre><code>$('document').ready(function(){ var spanOffset = $('.top').offset(); $(window).scroll(function() { if($(window).scrollTop() &lt; spanOffset.top) { $('.top').css({ 'position': 'static'}); } else { $('.top').css({ 'position': 'fixed', 'top': '0px'}); } }); }); </code></pre> <p>The logic behind the above snippet is pretty straight forward: We get the current Y offset of the <code>.top</code> and store it in a variable. When the window scrolls, we check the Y offset against the amount of distance scrolled. If the window does not scroll, the value of <code>$(window).scrollTop()</code> is essentially 0, and therefore, <code>.top</code> remains within the parent with no alteration; if the window scrolls and the scroll distance calculated by <code>$(window).scrollTop()</code> exceeds the current Y offset of <code>.top</code>, the CSS of <code>.top</code> will then be altered to "stick" it to the top of the window.</p> <p>Refer to <a href="http://jsfiddle.net/Jzz76/20/" rel="nofollow">http://jsfiddle.net/Jzz76/20/</a> for a working example.</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.
    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