How To Make Stage Transparent In Animate

How To Make Stage Transparent In Animate

How to create high-performance CSS animations

Kayce Basques

This guide teaches y'all how to create high-operation CSS animations.

Meet Why are some animations slow? to larn the theory backside these recommendations.

Browser compatibility #

All of the CSS properties that this guide recommends accept proficient cantankerous-browser support.

  • transform
  • opacity
  • will-change

Move an element #

To move an element, use the translate or rotation keyword values of the transform property.

For case to slide an particular into view, utilise translate.

                          .breathing              {              
blitheness : slide-in 0.7s both;
}

@keyframes slide-in {
0% {
transform : translateY (-1000px) ;
}
100% {
transform : translateY (0) ;
}
}

Items can likewise be rotated, in the case beneath 360 degrees.

                          .animate              {              
animation : rotate 0.7s ease-in-out both;
}

@keyframes rotate {
0% {
transform : rotate (0) ;
}
100% {
transform : rotate (360deg) ;
}
}

Resize an element #

To resize an element, use the scale keyword value of the transform belongings.

                          .animate              {              
animation : scale 1.5s both;
}

@keyframes scale {
50% {
transform : scale (0.5) ;
}
100% {
transform : scale (i) ;
}
}

Change an chemical element'due south visibility #

To show or hibernate an element, use opacity.

                          .breathing              {              
animation : opacity 2.5s both;
}

@keyframes opacity {
0% {
opacity : i;
}
50% {
opacity : 0;
}
100% {
opacity : i;
}
}

Avoid properties that trigger layout or paint #

Before using any CSS property for animation (other than transform and opacity), go to CSS Triggers to decide the holding's impact on the rendering pipeline. Avoid any property that triggers layout or paint unless absolutely necessary.

The top property detailed on CSS Triggers

Strength layer creation #

As explained in Why are some animations slow?, past placing elements on a new layer they can exist repainted without besides requiring the rest of the layout to exist repainted.

Browsers will often make good decisions nearly which items should exist placed on a new layer, but you lot can manually force layer creation with the will-alter property. Equally the name suggests, this holding tells the browser that this element is going to exist changed in some way.

In CSS this property can be practical to whatsoever selector:

                          body > .sidebar              {              
volition-change : transform;
}

However, the specification suggests this approach should merely be taken for elements that are e'er well-nigh to modify. If the in a higher place example was a sidebar the user could slide in and out, that might be the case. Some items on your page may not oft modify, and then information technology would exist better to apply will-change using JavaScript at a point where it becomes likely the alter will occur. You lot'll need to make sure to give the browser enough fourth dimension to perform the optimizations needed and then remove the holding once the changing has stopped.

If you lot need a way to forcefulness layer cosmos in i of the rare browsers that doesn't support will-change (most probable Net Explorer at this signal), you can set transform: translateZ(0).

Debug slow or janky animations #

Chrome DevTools and Firefox DevTools take lots of tools to help you figure out why your animations are ho-hum or janky.

Check if an animation triggers layout #

An animation that moves an element using something other than transform, is probable to be irksome. In the following case, I have achieved the same visual upshot animating top and left, and using transform.

Don't

                                                .box                  {                                
position : absolute;
elevation : 10px;
left : 10px;
animation : move 3s ease infinite;
}

@keyframes motility {
l% {
top : calc (90vh - 160px) ;
left : calc (90vw - 200px) ;
}
}

Practice

                                                .box                  {                                
position : absolute;
top : 10px;
left : 10px;
animation : movement 3s ease infinite;
}

@keyframes movement {
50% {
transform : translate ( calc (90vw - 200px) , calc (90vh - 160px) ) ;
}
}

You can exam this in the post-obit two Glitch examples, and explore performance using DevTools.

  • Before.
  • After.

Chrome DevTools #

  1. Open the Performance panel.
  2. Record runtime performance while your animation is happening.
  3. Inspect the Summary tab.

If you meet a nonzero value for Rendering in the Summary tab, information technology may mean that your blitheness is causing the browser to do layout piece of work.

The Summary panel shows 37ms for rendering and 79ms for painting.
The animation-with-summit-left example causes rendering work.
The Summary panel show zero values for rendering and painting.
The blitheness-with-transform example does non cause rendering piece of work.

Firefox DevTools #

In Firefox DevTools the Waterfall tin help you to empathise where the browser is spending fourth dimension.

  1. Open the Performance panel.
  2. In the panel Start Recording Performance while your blitheness is happening.
  3. Stop the recording and inspect the Waterfall tab.

If you lot run across entries for Recalculate Fashion then the browser is having to begin at the start of the rendering waterfall.

The Waterfall panel shows many entries for Recalculate Style.
The animation-with-peak-left case causes fashion recalculation.
The Waterfall panel shows no entries for Recalculate Style.
The blitheness-with-transform example does not cause style recalculation.

Bank check if an animation is dropping frames #

  1. Open the Rendering tab of Chrome DevTools.
  2. Enable the FPS meter checkbox.
  3. Picket the values as your blitheness runs.

At the peak of the FPS meter UI you run across the label Frames. Below that you run into a value along the lines of 50% i (938 grand) dropped of 1878. A high-performance animation will have a loftier percentage, eastward.yard. 99%. A loftier percentage ways that few frames are being dropped and the animation volition expect smoothen.

The fps meter shows 50% of frames were dropped
The animation-with-superlative-left instance causes l% of frames to be dropped
The fps meter shows only 1% of frames were dropped
The animation-with-transform example causes only 1% of frames to be dropped.

Check if an animation triggers paint #

When it comes to painting, some things are more expensive than others. For example, anything that involves a blur (like a shadow, for case) is going to take longer to paint than cartoon a crimson box. In terms of CSS, however, this isn't always obvious: background: scarlet; and box-shadow: 0, 4px, 4px, rgba(0,0,0,0.5); don't necessarily look like they have vastly unlike performance characteristics, but they practise.

Browser DevTools tin can assistance you to identify which areas need to exist repainted, and performance issues related to painting.

Chrome DevTools #

  1. Open up the Rendering tab of Chrome DevTools.
  2. Select Paint Flashing.
  3. Motility the arrow around the screen.
A UI element highlighted in green to demonstrate it will be repainted
In this case from Google Maps you can encounter the elements that will be repainted.

If you run across the whole screen flashing, or areas that you don't call back should modify highlighted and so you can do some investigation.

If y'all need to dig into whether a particular property is causing performance issues due to painting, the paint profiler in Chrome DevTools can assist.

Firefox DevTools #

  1. Open Settings and add a Toolbox button for Toggle paint flashing.
  2. On the page you want to inspect, toggle the button on and motion your mouse or curlicue to see highlighted areas.

Determination #

Where possible restrict animations to opacity and transform in gild to keep animations on the compositing stage of the rendering path. Utilize DevTools to check which stage of the path is existence affected by your animations.

Apply the paint profiler to run into if any paint operations are especially expensive. If yous detect anything, see if a different CSS property volition give the same look and feel with ameliorate performance.

Employ the will-change property sparingly, and only if you run into a performance upshot.

Last updated: — Better article

Return to all articles


DOWNLOAD HERE


How To Make Stage Transparent In Animate

Posted by: mooreoblie1983.blogspot.com

0 Response to "How To Make Stage Transparent In Animate"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel