DEV Community

Discussion on: Amazing Profile Card Hover Using HTML & CSS

 
danbmky profile image
Dan Bamikiya

I tested your fork;

  1. Open chrome dev-tools
  2. Select Rendering: dev-to-uploads.s3.amazonaws.com/up...
  3. Open the drawer by pressing Esc
  4. Select Paint flashing and Layer borders
  5. Then I hovered on the image (before and after applying will-change) and I saw no painting (screen flashing green) occurred in both cases and the layer borders were the same in both cases. That means the browser already optimized that animation.

If will-change was adding any more optimizations, there would have been more layers borders and less painting (in this case no paintings happened in both tests).

You could test it on your end to see if I missed anything.

Side-note:
For browsers that don’t support will-change, but benefit from layer creation, such as older versions of Safari and Mobile Safari, you need to use a 3D transform to force a new layer:
transform: translateZ(0);

More on enabling Layer Borders and enabling realtime Paint Flashing, borders meaning πŸ‘‰ Chromium's source code and Stackoverflow answer by Paul Irish (note the link to debug.cc in this answer is broken so just check the Chromium's source code I linked)

More resources:

Although it is a good property it shouldn't be used to promote elements to a new layer unnecessarily.

If you have promoted an element to a new layer, use DevTools to confirm that doing so has given you a performance benefit. Don't promote elements without profiling.

I also agree with you that if the element is going to be animated constantly (for example scroll animations) and there's a performance benefit its much better to use the will-change property in the stylesheets.

Side-note:
If anyone notices any performance benefit when testing this fork, know that will-change optimizations depends on the resources (memory, computing power) available to your browser, meaning it varies in user machines (both desktops, laptops and mobile phones). So me not seeing any optimizations could mean my machine has enough resources for my browser to optimize the animation itself.