Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create sliding DIV on click?

I am looking to create a slide out DIV, like the one here when you press "Contact". Does anybody know of anything similar to this?

like image 790
Earl Larson Avatar asked Nov 11 '11 23:11

Earl Larson


People also ask

How to slide up a div using jQuery?

The jQuery slideToggle() method toggles between the slideDown() and slideUp() methods. If the elements have been slid down, slideToggle() will slide them up. If the elements have been slid up, slideToggle() will slide them down. $(selector).

How to slide elements in jQuery?

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


1 Answers

If you don't want to use jQuery and you can stick to modern browsers you can try:

Demo: http://jsfiddle.net/ThinkingStiff/EVyE8/

HTML:

<div id="slide">click me</div>

CSS:

#slide {
    height: 50px;
    transition:             height 500ms ease;
        -moz-transition:    height 500ms ease;
        -ms-transition:     height 500ms ease;
        -o-transition:      height 500ms ease;
        -webkit-transition: height 500ms ease;
}

Script:

document.getElementById( 'slide' ).addEventListener( 'click', function() {

    this.style.height == '50px' || this.style.height == ''
        ? this.style.height = '150px' 
        : this.style.height = '50px';

}, false );
like image 196
ThinkingStiff Avatar answered Sep 18 '22 04:09

ThinkingStiff