pmiranda
pmiranda

Reputation: 8450

"show/hide" a div with javascript not jquery, and not with display:none

I need to show/hide up and down a div, but:

Til now, I only made that divs get the style visibility: hidden and block, by clickin some "Toggle" button, it works ok, but I don't know how to add some effect on the display, like togle('slow') does.

My CSS:

.show, .show * {
    visibility: inherit  !important;
}

.hide, .hide * {
    visibility: hidden !important;
}

My React/js:

toggleCharts:function(){
    //$("#chartBox").toggle();
    if (this.state.className === 'hide')
        this.setState({className: 'show'});
    else
        this.setState({className: 'hide'});
}

The Div to hide:

<div id="chartBox" className={this.state.className}></div>

Upvotes: 3

Views: 653

Answers (2)

Jon Uleis
Jon Uleis

Reputation: 18649

Keep your React/jQ as-is, but show and hide your elements with CSS transitions, like fading with opacity:

.show {
    opacity: 1 !important;
    transition: opacity .5s;
}

.hide {
    opacity: 0 !important;
    transition: opacity .5s;
}

Upvotes: 3

Taki
Taki

Reputation: 17654

try : $('#chartBox').animate({opacity : 0}, 500);

Upvotes: 1

Related Questions