Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why CSS3 Animation is not working?

Can someone help me to find out why animation on <h5> element doesn't work?

#hero h5 {
  animation: fadein 2s;
  -moz-animation: fadein 2s; /* Firefox */
  -webkit-animation: fadein 2s; /* Safari and Chrome */
  -o-animation: fadein 2s; /* Opera */
  font-weight: strong;
  font-size: 28px; 
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<section id="hero">
    <div class="content">
        <div class="container">
            <div class="row">
                <h5>Lorem Ipsum Demo Title</h5>
            </div><!-- row -->
        </div> <!-- container -->
    </div> <!-- content -->
</section><!-- section -->      
like image 265
Morgari Avatar asked Jan 17 '17 06:01

Morgari


People also ask

Can we create animation using css3?

CSS allows animation of HTML elements without using JavaScript or Flash! In this chapter you will learn about the following properties: @keyframes. animation-name.

What is the CSS 3 rule that allows for animations?

The @keyframes rule specifies the animation code. The animation is created by gradually changing from one set of CSS styles to another. During the animation, you can change the set of CSS styles many times.

Which CSS properties Cannot be animated?

CSS properties that define animation parameters such as animation-direction and animation-name are not animatable because animating them would create complex recursive behavior.


3 Answers

You are calling fadein animation in your code but you haven't defined it anywhere.

CSS3 animations are defined with @keyframes rule. More Information about CSS3 animations is Here.

Add following css:

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

#hero h5 {
  animation: fadein 2s;
  -moz-animation: fadein 2s; /* Firefox */
  -webkit-animation: fadein 2s; /* Safari and Chrome */
  -o-animation: fadein 2s; /* Opera */
  font-weight: strong;
  font-size: 28px; 
}

@keyframes fadein {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<section id="hero">
  <div class="content">
    <div class="container">
      <div class="row">
        <h5>Lorem Ipsum Demo Title</h5>
      </div><!-- row -->
    </div> <!-- container -->
  </div> <!-- content -->
</section><!-- section -->      
like image 90
Mohammad Usman Avatar answered Sep 21 '22 09:09

Mohammad Usman


#hero h5 {
     font-weight: strong;
     font-size: 28px; 
 -webkit-animation-delay: 0.7s;
  -moz-animation-delay: 0.7s;
  animation-delay: 0.7s;
}

@-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.fade-in {
  opacity:0;
  -webkit-animation:fadeIn ease-in 1;
  -moz-animation:fadeIn ease-in 1;
  animation:fadeIn ease-in 1;

  -webkit-animation-fill-mode:forwards;
  -moz-animation-fill-mode:forwards;
  animation-fill-mode:forwards;

  -webkit-animation-duration:1s;
  -moz-animation-duration:1s;
  animation-duration:1s;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<section id="hero">
        <div class="content">
            <div class="container">
                <div class="row">
                <h5 class="fade-in">Lorem Ipsum Demo Title</h5>
 
                </div><!-- row -->
            </div> <!-- container -->
        </div> <!-- content -->
</section><!-- section -->   




  
like image 41
Jatin Kalra Avatar answered Sep 21 '22 09:09

Jatin Kalra


You must define a animation named fadeIn - as shown below.

Currently, you are using an animation but you have never created it.

@keyframes fadeIn {
    0% {
        transform: translate(0,0)
    }
    30% {
        transform: translate(5px,0)
    }
    55% {
        transform: translate(0,0)
    }
   80% {
        transform: translate(5px,0)
    }
    100% {
        transform: translate(0,0)
    }
}
like image 41
UnUsuAL Avatar answered Sep 20 '22 09:09

UnUsuAL