Hamza Shatela Official Website. Web Design, SEO & Online Marketing Professional.
  • BLOG
  • CONTACT

Hamza Shatela

Join The 1 Year WordPress Program
  • Home
  • Blog
  • Coding
  • Animating elements with CSS Keyframes
December 10, 2017

Animating elements with CSS Keyframes

Animating elements with CSS Keyframes

by Shatela Hamza / Sunday, 19 November 2017 / Published in Coding, Css
Animating elements with CSS Keyframes

Syntax and What it Does.

Animation in CSS helps you manipulate an element on your website in a stylish way. Whether you want an element to bounce up and down ten times, or continuously change colors, Keyframes help you do that.

Syntax

.yourCustomClassOrID{
animation-name: myAnimationName;
animation-duration: 6s ; /* or 6000ms */
animation-iteration-count: 2; /* or infinite */
animation-direction: normal; /* or alternate */
animation-delay: 1s; /* or 1000ms */
animation-fill-mode: both; /* or backwards, forwards, none */
animation-timing-function: ease; /* or ease-in, ease-out, ease-in-out, linear, cubic-bezier()*/}

However, there is a shorthand for this property, and it goes like this:

.yourCustomClassOrID{
animation: myAnimationName duration delay iteration-count direction fill-mode;}
Order doesn’t matter if you don’t have your duration and delay set, otherwise you have to follow this order.

To start styling your animation, we use the @keyframes rule, which is what manipulates the element from one style to another:

@keyframes myAnimationName{
from{ color: white }
to{ color: red }
/*From white color to red color within the duration you set in the animation property */}

Sounds easy right? Well, for this property, you also need to include prefixes to support cross-browser compatibility, and the way you initialize prefixes is the following:

.yourCustomeClassOrID{
-webkit-animation: myAnimationName 3s infinite; /* Safari 4.0 – 8.0 */
-o-animation: myAnimationName 3s infinite;  /* Opera 12.0+ */
-moz-animation: myAnimationName 3s infinite;  /* FireFox 5.0+ */
animation: myAnimationName 3s infinite; /* IE 10.0+ */}

@-webkit-keyframes yourAnimationName{
0%{ background-color: red }
50%{ background: yellow }
100%{ background: blue }
}

@-moz-keyframes yourAnimationName{
0%{ background-color: red }
50%{ background: yellow }
100%{ background: blue }
}

@-o-keyframes yourAnimationName{
0%{ background-color: red }
50%{ background: yellow }
100%{ background: blue }
}

@keyframes yourAnimationName{
0%{ background-color: red }
50%{ background: yellow }
100%{ background: blue }
}
/*Any % from 0% to 100% can be used to set intervals between each animation*/

Animation Example

This concludes Animating with keyframes. The only limit to animating with keyframes is your imagination, so go out and and start animating!

Feel free to share
Shatela Hamza

About Shatela Hamza

Hamza Shatela is a web designer and online business developer. With ten years of experience in the digital marketing field. As the founder of Slide Sigma, he has worked with a series of professionals from the medical, financial, nonprofit, and entertainment industries.

What you can read next

Add Custom CSS To WordPress Post or Page
Add Custom CSS To WordPress Post or Page

WEBSITE HOSTING


Bluehost.com $3.95 Hosting

SEO PowerSuit

SEO PowerSuit free Downlaod

Constant Contact 60 Days Free

constant contact form downlaod

RankPay

RankPay SEO Services

SEMrush

Recent Posts

  • How to Install WordPress Tutorial

    How to Install WordPress – Complete WordPress Installation Tutorial 101

  • Multisites WordPress

    How to Install a Multisites on WordPress

  • Install WordPress using FTP

    How to Install WordPress using FTP (Manual Installation)

  • Install WordPress MOJO Marketplace

    How to Install WordPress Using MOJO Marketplace

  • Install WordPress Fantastico

    How to Install WordPress using Fantastico

Sign up and join 38,371+ of other smart subscribers. Stay up to date with weekly newsletter on market trends and stay on top of your online buiness by having an idepth knowledge of valuable softwares to boost your online business

What do you have to lose? You can unsubscribe anytime.

About

  • About Me

Additional Pages

  • Blog
  • Start a Blog for Free
  • WordPress 1 Year Program

Legal

  • Privacy Policy
  • Term & Conditions
  • Disclosure

Contact

  • Contact

My reviews and opinion on sites are ranked and reviewed on the basis of my own views and expert opinions. I use affiliate links, and I get a commission when you click on any referral website. That’s how I maintain this website. It doesn’t cost you anything. In fact, I guarantee you get the best price when you use my link. Hamzashatela.com cannot and does not present information about every site or site offer available.
© 2017 Hamzashatela. All rights reserved.

TOP