Reputation: 569
I want to make a footer that is expandable when you click the '+' sign.. Initially, I have a very small footer with only copyright information and social media links. When the sign is clicked, I want a sitemap (and some other things) to slide above the copyright information.
However, I need to make sure that the page remains scrolled down entirely. If not, the panel will slide, but you won't be able to see it..
This is what I now have:
HTML
<div id="footer-wrapper" class="clearfix">
<footer>
<span id="footer-expander">+</span>
<section id="footer-hidden" class="clearfix">
<section id="sitemap" class="cols-3">
<h1>Sitemap</h1>
<ul>
<li><a href="">Home</a></li>
<li><a href="">About</a></li>
<li><a href="">Portfolio</a></li>
<li><a href="">Blog</a></li>
<li><a href="">Contact</a></li>
</ul>
</section>
<section class="cols-3">
<h1>Something else</h1>
</section>
<section class="cols-3">
<h1>Last, but not least.</h1>
</section>
</section>
<section id="footer-show" class="clearfix">
<p>© Helena Standaert.</p>
<section id="btm-socialmedia" class="socialmedia">
<ul>
<li class="twitter"><a href="">Twitter</a></li>
<li class="facebook"><a href="">Facebook</a></li>
<li class="linkedin"><a href="">LinkedIn</a></li>
<li class="rss"><a href="">RSS-feed</a></li>
</ul>
</section>
</section>
</footer>
</div>
JQUERY
$('#footer-expander').click(function(){
$('#footer-hidden').slideToggle('slow', function(){
goToByScroll('footer-wrapper')
if($('#footer-expander').html('-')){
$('#footer-expander').html('+');
}
if($('#footer-expander').html('+')){
$('#footer-expander').html('-');
}
});
})
Upvotes: 3
Views: 817
Reputation: 16103
Simplefied, make a scroll interval which gets turned off by the scroll
var pageScroller = setInterval(function(){
scrollTo(0, document.scrollHeight)}, // Scroll to bottom
100 // every 100 ms correct. Can be 50, or 25, or whatever
);
$('#footer-hidden').slideToggle(600, function(){
clearInterval( pageScroller ); // stop the interval which was scrolling
});
Upvotes: 1
Reputation: 61
The easier way would be to use the STEP option of sliteToggle.
Just update your javascript with the following (change FOOTER_CONTAINER by the appropriate element which should be your footer's wrapper) :
$('#footer-expander').click(function(){
$('#footer-hidden').slideToggle({duration: 'slow', step: function(){
$(FOOTER_CONTAINER).scrollIntoView(false);
}, complete: function(){
goToByScroll('footer-wrapper')
if($('#footer-expander').html('-')){
$('#footer-expander').html('+');
}
if($('#footer-expander').html('+')){
$('#footer-expander').html('-');
}
}});
});
With this, the function
$(FOOTER_CONTAINER).scrollIntoView(false);
will be called at every step and will scroll your container into view (false aligns it with the bottom).
Upvotes: 0