<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zheng Zhao on Medium]]></title>
        <description><![CDATA[Stories by Zheng Zhao on Medium]]></description>
        <link>https://medium.com/@fishzhao?source=rss-1142ff23355b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2yQrI-oDN-J7qV3WB8TVMA@2x.jpeg</url>
            <title>Stories by Zheng Zhao on Medium</title>
            <link>https://medium.com/@fishzhao?source=rss-1142ff23355b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:08:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fishzhao/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Optimised Animation with CSS3]]></title>
            <link>https://medium.com/@fishzhao/optimised-animation-with-css3-c3f4416475e2?source=rss-1142ff23355b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3f4416475e2</guid>
            <category><![CDATA[digital-design]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Zheng Zhao]]></dc:creator>
            <pubDate>Mon, 28 Oct 2019 22:20:52 GMT</pubDate>
            <atom:updated>2019-10-28T22:28:49.783Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*15tMkxG-7qZEmP3hVjr3Gw.jpeg" /></figure><p>In this post, we will discuss best practices to take into account to achieve the animation in a buttery smooth fashion.</p><h3>Critical Rendering Path</h3><p>First thing first, let’s talk about this fundamental mechanism behind our browsers. <strong>Critical Rendering Path</strong> is a timeline of what the browser does in the intermediate steps between receiving the HTML, CSS, and JavaScript bytes and the required processing to turn them into rendered pixels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*mbdXoVBAWJjRr48L7jtfYQ@2x.jpeg" /></figure><h4>Step 1: Styles</h4><p>The browser starts calculating the styles to apply in elements — Recalculate <strong>Style</strong>.</p><h4>Step 2: Layout</h4><p>In the following layer, the browser will start generating the shape and position for each of those elements <strong>Layout</strong> –properties such as <strong>width</strong> and <strong>height</strong>, as well as its <strong>margins</strong>, or <strong>left</strong>/<strong>top</strong>/<strong>right</strong>/<strong>bottom</strong> for instance.</p><h4>Step 3: Paint</h4><p>The browser will now start filling in the pixels for each element into layers. The properties that it uses are, for instance: <strong>box-shadow</strong>, <strong>border-radius</strong>, <strong>color</strong>, <strong>background-color</strong>, among others.</p><h4>Step 4: Composite</h4><p>The browser starts drawing all the layers in the screen making use of the transform and opacity properties.</p><ul><li>Position — transform:<strong> translateX(n) translateY(n) translateZ(n)</strong>;</li><li>Scale — transform:<strong> scale(n)</strong>;</li><li>Rotation — transform: <strong>rotate(ndeg)</strong>;</li><li>Opacity —<strong> opacity: n;</strong></li></ul><p>To achieve smooth animations we need to focus on changing properties that affect the <strong>Composite</strong> step, instead of adding this stress to the previous layers.</p><h3>How We Usually Do It in the Wrong Way</h3><p>Going after properties like <strong>right</strong> or <strong>margin-right</strong> to create the animation forces the browser creating layouts each time, which will affect all of their children.</p><p>Therefore we should avoid using the <strong>left</strong>/<strong>top</strong>/<strong>right</strong>/<strong>bottom</strong> and the <strong>margin</strong> properties.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fembed%2Fpreview%2FNJVyYQ%3Fheight%3D600%26slug-hash%3DNJVyYQ%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fpen%2FNJVyYQ&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2085933.NJVyYQ.small.1332d829-b4cf-4e80-becf-7f5951615ac4.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4d0cb55b31a7d777eef58e15310c113/href">https://medium.com/media/a4d0cb55b31a7d777eef58e15310c113/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fembed%2Fpreview%2FmoYXOK%3Fheight%3D600%26slug-hash%3DmoYXOK%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fpen%2FmoYXOK&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2085933.moYXOK.small.21335cf0-4917-4aec-9b8c-b2dd09fca6bf.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/87397bca2b1d60082b194839ca99ad7e/href">https://medium.com/media/87397bca2b1d60082b194839ca99ad7e/href</a></iframe><h3>Transform Comes to Rescue</h3><p>The transform properties affect a Composite. Here we’re telling the browser that layers will be painted and ready to go as soon as the animation starts, so there are fewer hiccups when rendering the animation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fembed%2Fpreview%2FOqevBy%3Fheight%3D600%26slug-hash%3DOqevBy%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fpen%2FOqevBy&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2085933.OqevBy.small.d9edf62e-6997-4e04-91e8-fb2840e07616.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/48fbe725f1e785f03642d1432d1b58ba/href">https://medium.com/media/48fbe725f1e785f03642d1432d1b58ba/href</a></iframe><h3>Bonus: Hardware-Accelerated CSS</h3><p>CSS animations, transforms and transitions are not automatically GPU accelerated, and instead execute from the browser’s slower software rendering engine. So what exactly forces the browser to swap to GPU mode? Many browsers provide GPU acceleration by means of certain CSS rules.</p><p>Currently, browsers like Chrome, FireFox, Safari, IE9+ and the latest version of Opera all ship with hardware acceleration; they only use it when they have an indication that a DOM element would benefit from it. With CSS, the strongest indication is that a 3D transformation is being applied to an element.</p><p>The will-change property promotes the elements to another layer, so the browser doesn’t have to consider the layout render or painting.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fembed%2Fpreview%2FmoZxNy%3Fheight%3D600%26slug-hash%3DmoZxNy%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Ffixfish%2Fpen%2FmoZxNy&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2085933.moZxNy.small.6ed836b8-453a-4c3f-b785-cf9a36b12fe1.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/737d572cf2ab6ee0af645a69f2105093/href">https://medium.com/media/737d572cf2ab6ee0af645a69f2105093/href</a></iframe><p>We can use JavaScript to append additional class names in order to activate/deactivate the product image like the following:</p><h4>JavaScript</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba477896985e3adc074d2e25099b3f34/href">https://medium.com/media/ba477896985e3adc074d2e25099b3f34/href</a></iframe><h4>CSS</h4><p>Then apply different transform values to the original and .active classes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb7981588071e1298c57b0fb1ad0da2d/href">https://medium.com/media/eb7981588071e1298c57b0fb1ad0da2d/href</a></iframe><p>The problem here is that by adding that class within the menu div, we made the browser recalculate styles one more time — and that affects the rendering performance.</p><h4>HTML</h4><p>Inheriting the CSS and JavaScript above, here’s a revised HTML structure where it has the animated image part in an isolated area. This will ensure that you only affect the element that you really want to animate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0266f8f9d431c1c246b8e4e9afa147e6/href">https://medium.com/media/0266f8f9d431c1c246b8e4e9afa147e6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3f4416475e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>