简体   繁体   中英

Can I hide/show this menu with CSS3 and or javascript without a timeout

http://jsfiddle.net/blankasaurus/YPR4U/15/embedded/result/

I have the layout functioning how I want it to function. I'm not sure I like having to set the width in the toggle function:

 $('.content').css('width', '100%');

 $('.content').css('width', '75%');

and I also REALLY don't like having to set a timeout before showing and hiding the menu panel:

 setTimeout(function()
 {
     $('.sidebar').fadeIn();
 }, 1001);

Is there a better way to go about this?

Here's a fiddle:

For the fading out, you can just use a callback function passed into fadeOut .

For example:

$('.sidebar').fadeOut( 400, function() {
    $('.content').css('width', '100%');
});

For the fading in, you could try using transition events . You'll just have to write specific code for different browsers, and not surprisingly, older browsers are not supported. More details can be found here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM