Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading image using CSS animation VS loading using GIF image

I encounter a problem showing loading a CSS animation while doing a heavy JavaScript operation, so wondering if CSS animation is taking more resources than showing a simple loading GIF image, I made the following tests.

1 created page with loading CSS

  1. Created page with loading CSS animation
  2. Created page with loading GIF image
  3. Compared their resources using Chrome task manager

Here are the results:

It looks like CSS animation is using more CPU, and more memory so basically I want to consult about using CSS animations. Isn't that too heavy? Should I avoid using it in loading cases?

Loading example using CSS animation

Loading example using GIF image

CSS loading animation compare to GIF loading image

Here is the code for loading with CSS animation

CSS

/* Beautiful loading screen */
#loadingWrap{
  width: 100%;
  height: 100%;
  top: 0px;
  z-index: 250;
  background-color: rgba(255, 255, 255, 0.46);
}
.glyphicon.spin {
  font-size: 36px;
  -webkit-animation: spin 1.822s infinite linear;
  -moz-animation: spin 1.822s infinite linear;
  -o-animation: spin 1.822s infinite linear;
  animation: spin 1.822s infinite linear;
  -webkit-transform-origin: 50% 58%;
  transform-origin:50% 58%;
  -ms-transform-origin:50% 58%; /* IE 9 */
  line-height: 0px;
}

@-moz-keyframes spin {
  from {    -moz-transform: rotate(0deg);  }
  to {    -moz-transform: rotate(360deg);  }
}

@-webkit-keyframes spin {
  from {-webkit-transform: rotate(0deg);}
  to {-webkit-transform: rotate(360deg);}
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to {transform: rotate(360deg); }
}
#loadingIcon {
  z-index: 10;
  position: absolute;
  right: 20px;
  bottom: 20px;
  line-height: 0px;
}

HTML

<div id="loadingWrap">
   <div id="loadingIcon">
      <i class="glyphicon glyphicon glyphicon-cog spin">Q</i>
   </div>
</div>

Here is the code for loading using a simple GIF image

CSS

#loadingWrap{
      width: 100%;
      height: 100%;
      top: 0px;
      z-index: 250;
      background-color: rgba(255, 255, 255, 0.46);
 }
 #loadingIcon {
      z-index: 10;
      position: absolute;
      right: 20px;
      bottom: 20px;
      line-height: 0px;
      background: url(../1-0.gif) no-repeat center center;
      width: 20px;
      height: 20px;
 }

HTML

<div id="loadingWrap">
   <div id="loadingIcon">
   </div>
</div>
like image 806
talsibony Avatar asked Jun 28 '15 07:06

talsibony


People also ask

Does CSS animation affect performance?

Compared with animating elements using JavaScript, CSS animations can be easier to create. They can also give better performance, as they give the browser more control over when to render frames, and to drop frames if necessary.

Is CSS animation faster than JavaScript?

The fact is that, in most cases, the performance of CSS-based animations is almost the same as JavaScripted animations — in Firefox at least. Some JavaScript-based animation libraries, like GSAP and Velocity. JS, even claim that they are able to achieve better performance than native CSS transitions/animations.

How do you animate smoothly in CSS?

The animation-timing-function specifies the speed curve of an animation. The speed curve defines the TIME an animation uses to change from one set of CSS styles to another. The speed curve is used to make the changes smoothly.

What is CSS animation used for?

CSS animations make it possible to animate transitions from one CSS style configuration to another. Animations consist of two components, a style describing the CSS animation and a set of keyframes that indicate the start and end states of the animation's style, as well as possible intermediate waypoints.


1 Answers

Gif images:

  • Positives

    • Performance (small file size)
    • Ease of use & setup
    • Older browser support
  • Negatives:

    • Don't scale smoothly (retina displays, larger images)
    • Image quality(256 color limit)
    • Difficult adaptation & change (need specialized software like Photoshop)

Css animations:

  • Positives:

    • Easily editable through CSS
    • High quality images and rich colors possible
    • Smooth scaling (retina ready images & svgs)
  • Negatives:

    • Performance
    • CSS animations not supported by IE 7,8,9
    • More complex to setup
like image 154
Roumelis George Avatar answered Sep 20 '22 17:09

Roumelis George