Note that there are some explanatory texts on larger screens.

plurals
  1. POShow footer if at bottom of page or page is short else hide
    primarykey
    data
    text
    <p>Check out my jsFiddle to see what is going on: <a href="http://jsfiddle.net/Amp3rsand/EDWHX/2/">http://jsfiddle.net/Amp3rsand/EDWHX/2/</a></p> <p>If you uncomment the second .content div in the article you will see the footer hiding like it should then un-hiding when you get to the bottom of the page. My trouble is that I would like it to show the footer when the content is shorter than the viewport like when the second .content div is commented out.</p> <p>(ie. window.height > document.height right?)</p> <p>On my actual website the .content divs are replaced by different divs with unique id's for each page so I couldn't figure out how to target them specifically. Is what I'm doing the correct way to do it?</p> <p>Here is my code for the people who don't want to use the jsFiddle for some reason:</p> <p>HTML</p> <pre><code>&lt;article&gt; &lt;div class="content"&gt;&lt;/div&gt; &lt;!-- &lt;div class="content"&gt;&lt;/div&gt; --&gt; &lt;/article&gt; &lt;footer&gt; &lt;ul id="footerlinks"&gt; &lt;li&gt;&lt;a href="#"&gt;home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;contact&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/footer&gt; &lt;div id="underfooter"&gt;&lt;/div&gt; </code></pre> <p>CSS</p> <pre><code>article { min-height: 500px; background: black; padding: 10px; margin-bottom: 50px; } .content { height:500px; background: lightgrey; border: 1px dashed red; } footer { position: fixed; bottom: -50px; height: 40px; width: 100%; margin: 0 auto; text-align: center; border-top:2px solid #6ce6d5; background: white; z-index: 100; } #underfooter { position: fixed; bottom: -44px; background: blue; width: 100%; height: 40px; z-index: 90; } </code></pre> <p>JQuery</p> <pre><code>$(function(){ $('footer').data('size','hide'); }); $(window).scroll(function(){ if ($(window).scrollTop() + $(window).height() &gt;= $(document).height() - 0) { if($('footer').data('size') == 'hide') { $('footer').data('size','show'); $('footer').stop().animate({ bottom:'0px' },400); $('#white2').stop().animate({ bottom:'6px' },400); } } else { if($('footer').data('size') == 'show') { $('footer').data('size','hide'); $('footer').stop().animate({ bottom:'-50px' },400); $('#white2').stop().animate({ bottom:'-44px' },400); } } }); $(document).ready(function() { if ($(window).height() &gt;= $(document).height() ) { $('footer').data('size','hide'); } else { $('footer').data('size','big'); } }); </code></pre> <p>Thanks everyone</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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