Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to slide content opening up with jquery

My designer handed me a design I'm not 100% sure how to do with jquery and css. I am basicly trying to allow a user to "slide" the footer up to reveal more conent.

My html..

 <div id="footer">
     <div id="expandingFooter"> hidden content</div>
        content that is always visible
 </div>

I have a toggle button that onclick

$('#expandingFooter').slideToggle();

This slides the expanding footer content open downward, then slides back up to close. I would like it to slide up and then close down.

Thanks

like image 270
studiothat Avatar asked Dec 12 '08 18:12

studiothat


People also ask

How to slide content with jQuery?

The jQuery slideUp() method is used to slide up an element. Syntax: $(selector). slideUp(speed,callback);

How to make a div slide down with jQuery?

The slideDown() method slides-down (shows) the selected elements. Note: slideDown() works on elements hidden with jQuery methods and display:none in CSS (but not visibility:hidden). Tip: To slide-up (hide) elements, look at the slideUp() method.

Which jQuery method is used to slide down an element?

jQuery | slideDown() Method The slideDown() Method in jQuery is used to check the visibility of selected elements or to show the hidden elements.


1 Answers

You can leverage JQuery UI 1.6's Effects (Effects Demo Page). The following accomplished the desired effect for me.

$('#toggleButton').bind('click', function(e) {
    $('#expandingFooter').toggle(
        'slide', 
        { easing: 'easeOutQuint', direction: 'down' }, 
        1000
    );
});

Note: You may want to play with the easing parameter to get the desired smoothness of the effect.

You'll need to have the latest versions of both JQuery and JQuery UI Slide Effect to do this.

like image 144
Manik Avatar answered Nov 15 '22 06:11

Manik