Note that there are some explanatory texts on larger screens.

plurals
  1. POStatic and Sticky fixed header transition misfunction
    primarykey
    data
    text
    <p>I created a sticky header based on scroll even but there are two problems:</p> <ol> <li>When scrolling up and down, there is jump at background. (I hope you understand what I mean)</li> <li>Sometimes both header divs appear together.</li> </ol> <p>How can I solve the problem?</p> <p>Thanks in advance</p> <p><a href="http://jsfiddle.net/ezBXc/" rel="nofollow">JSFiddle Demo</a></p> <p><strong>CSS:</strong></p> <pre><code>* { margin: 0; padding: 0; } #header, #page, #footer { float: left; display: block; width: 100%; } #header { background: #CCCCCC; } #default { display: block; height: 100px; background: #64D989; } #sticky { display: none; height: 50px; background: #D9D164; } #footer { background: #EEEEEE; } </code></pre> <p><strong>JS:</strong></p> <pre><code>$(document).ready(function() { $(window).bind("scroll", function(e) { if ($(document).scrollTop() &gt; 100) { $("#header").css('position', 'fixed'); $("#default").css('display', 'none'); $("#sticky").css('display', 'block'); } else { $("#header").css('position', 'relative'); $("#sticky").css('display', 'none'); $("#default").css('display', 'block'); } }); }); </code></pre> <p><strong>HTML:</strong></p> <pre><code>&lt;div id="header"&gt; &lt;div id="default"&gt;I AM DEFAULT HEADER&lt;/div&gt; &lt;div id="sticky"&gt;I APPEAR IF SCROLL POSITION &gt; 100px&lt;/div&gt; &lt;/div&gt; &lt;div id="page"&gt; START&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; CONTENT&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; END &lt;/div&gt; &lt;div id="footer"&gt;I AM PAGE FOOTER&lt;/div&gt; </code></pre>
    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.
 

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