0

My Question

Is it possible to temporarily hide an element and then show it again after X milliseconds using CSS3?

A Brief Explanation...

I am currently building a responsive site, on which the sidebar changes size dependant on the size of the screen, as do the navigation icons on the sidebar.

Before the sidebar resizes it's width, I would like to fade out my navigation icons, and then fade them back in once the sidebar has finished animating.

See this example:

Sidebar Example

I have the following steps:

  1. Screen gets resized
  2. The navigation icons fade out
  3. Once the navigation icons are invisible, the sidebar resizes
  4. Once the sidebar has resized, the navigation icons fade back in but this time have different styles applied so they are smaller... (Not sure how to do this part...)

The way I animate the size of the sidebar is as follows:

@media all and (max-width: 1060px) {

    /* Define the Sidebar */
    #sidebar {width:60px !important;}

    /* Define the Sidebar Animation */
    /* The delay ensures it does not resize until the icons have disappeared */
    #sidebar {transition: width 300ms ease 300ms;}

}
Ben Carey
  • 16,540
  • 19
  • 87
  • 169
  • Too much steps, but too less code you've shared here to work with... – Mr. Alien Feb 19 '14 at 14:03
  • As far as fadein fadeout goes with CSS, you can refer my answer [here](http://stackoverflow.com/questions/16344354/how-to-make-blinking-flashing-text-with-css3/16344389#16344389) – Mr. Alien Feb 19 '14 at 14:04
  • @Mr.Alien The answer you have linked to looks like it could definitely be a step in the right direction. I do not know how to explain better what it is I am trying achieve, this is why I have included an image to help me explain... As for the code, there is no more than that needed to animate the width of the sidebar, and I do not know where to start for the navigation icons so I have not posted anything. Would it help if I posted a little HTML? – Ben Carey Feb 19 '14 at 14:08
  • No doubt you explained it thoroughly still, we debug the codes and we don't write new ones right? Anyways will try to help you once I get home.. :) – Mr. Alien Feb 19 '14 at 14:12
  • @Mr.Alien I am just having a play with keyframes as noted in your other answer. I will let you know if I sort it before you spend time on it :-) Thanks – Ben Carey Feb 19 '14 at 14:15

1 Answers1

2

Following the idea from @Mr.Alien, I was able to achieve what you wanted as a final animation for your sidebar and navigation. You can check the JS FIDDLE DEMO to see it in action. Obviously, I have not played with values much, so there's always area for improvement. But I think, you will get the idea, @Ben. Please check on chrome or Safari as I haven't put any other vendor prefixes than -webkit. You can resize the fiddle window to check it. :)

#sidebar {
    width: 250px;
    -webkit-transition: width 1s ease;
}

#nav img {
    width: 100px;
}

@media all and (max-width: 700px) {
    #sidebar {
        width:100px;
    } 
    #nav img {
         width: 50px;
        -webkit-animation-name: comeBackSmaller;
        -webkit-animation-duration: 0.8s;
        -webkit-animation-timing-function: linear;
        -webkit-animation-iteration-count: 1;
    }  
    @-webkit-keyframes comeBackSmaller {  
        0% { opacity: 1.0; width: 100px; }
        25% { opacity: 0.0; width: 75px; }
        50% { opacity: 0.0; width: 25px; }
        100% { opacity: 1.0; width: 50px; }
    }
}
Dhiraj
  • 1,871
  • 1
  • 12
  • 15
  • Thank you for your answer. This is similar to what I came up with using @Mr.Alien's tips... Unfortunately the CSS isn't quite effective enough to be used in this situation as I cannot prevent it from applying the aniamtion on page load. Resultantly I will have to use javascript instead. Thanks for your answer anyway +1 :-) – Ben Carey Feb 20 '14 at 12:19
  • Bit late now, but could you separate the animation classes and just add them (using javascript/jquery) after the page has loaded perhaps? – John Lucas Apr 16 '14 at 16:33