<?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 Dan Danciu on Medium]]></title>
        <description><![CDATA[Stories by Dan Danciu on Medium]]></description>
        <link>https://medium.com/@dan.danciu13?source=rss-f07569e147d6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*UgrZG-Y4nVKUwdUKTWPJGw.jpeg</url>
            <title>Stories by Dan Danciu on Medium</title>
            <link>https://medium.com/@dan.danciu13?source=rss-f07569e147d6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:27:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dan.danciu13/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[Smoothest performance for box-shadow animations with scss]]></title>
            <link>https://medium.com/@dan.danciu13/smoothest-performance-for-box-shadow-animations-with-scss-bba646a06bf2?source=rss-f07569e147d6------2</link>
            <guid isPermaLink="false">https://medium.com/p/bba646a06bf2</guid>
            <category><![CDATA[opacity]]></category>
            <category><![CDATA[box-shadow]]></category>
            <category><![CDATA[css-animation]]></category>
            <category><![CDATA[scss]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Dan Danciu]]></dc:creator>
            <pubDate>Sat, 10 Aug 2019 10:46:52 GMT</pubDate>
            <atom:updated>2019-08-10T10:46:52.647Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OHfFhy84M2hY8fM5" /><figcaption>Photo by <a href="https://unsplash.com/@stefanopollio?utm_source=medium&amp;utm_medium=referral">Stefano Pollio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>First you must understand why animating box-shadows is such a performance hit and why animating properties like transform and opacity is the greatest thing since fried chicken.</p><p>This article however does not mean to elaborate on either of those topics so what you can do ::before or ::after having a go at the implementation below, is to look at the following article which is basically the source of this idea. (see what I did there?)</p><p><a href="https://tobiasahlin.com/blog/how-to-animate-box-shadow/">Article by Tobias Ahlin</a></p><p>This article elaborates on that original idea by using both the ::before and ::after pseudo elements. It’s main purpose is to make it into reusable code that can be easily included in your projects with minimum effort.</p><p>Here is the whole thing upfront, so just hover the box:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fdan-danciu%2Fembed%2Fpreview%2FoKazMe%3Fheight%3D600%26slug-hash%3DoKazMe%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fdan-danciu%2Fpen%2FoKazMe&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2700460.oKazMe.small.4920dd2c-bbf6-4cbe-b143-6e6f46229fc3.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/1f2a6263a189e6f6d62d490ac1493af7/href">https://medium.com/media/1f2a6263a189e6f6d62d490ac1493af7/href</a></iframe><p>Now for a bit of an explanation read on.</p><h3>The mixins</h3><h4>BoxShadow</h4><p>It accepts one parameter which is the elevation of the element in dps. This whole thing is based off of <a href="https://material.io/design/">google’s material design</a>.</p><blockquote>Elevation in Material Design is measured as the distance between Material surfaces. The distance from the front of one Material surface to the front of another is measured along the z-axis in density-independent pixels (dps) and depicted (by default) using <a href="https://material.io/design/environment/elevation.html#depicting-elevation">shadows</a></blockquote><h4>animateShadowSetup</h4><p>This one accepts two parameters: the initial elevation of the element and the final elevation of the element.</p><p>First we set some common properties for both pseudo elements:</p><pre>&amp;::before, &amp;::after {<br>  content: &#39;&#39;;<br>  position: absolute;<br>  left: 0;<br>  right: 0;<br>  top: 0;<br>  bottom: 0;<br>  transition: opacity .3s ease-in-out;<br>  z-index: -1;<br>}</pre><p>Let’s break it down.</p><p>content: &#39;&#39;; this is required in order for the pseudo element to display.</p><p>position: absolute; we need this to be able to position it so it covers the entire parent element, which is exactly what the next four lines do as well.</p><p>left: 0; right: 0; top: 0; bottom: 0; stretch the pseudo element to cover the whole parent.</p><p>transition: opacity .3s ease-in-out; sets a nice transition for the opacity of this pseudo element.</p><p>z-index: -1; this is basically a must for pseudo elements, otherwise it can cause issues especially if you need to click on the parent or any other children.</p><p>Then watch the differences between the two:</p><pre>&amp;::before {<br>  <a href="http://twitter.com/include">@include</a> BoxShadow($dp_from);<br>  opacity: 1;<br>}<br>&amp;::after {<br>  <a href="http://twitter.com/include">@include</a> BoxShadow($dp_to);<br>  opacity: 0;<br>}</pre><p>@include BoxShadow($dp_from); this sets the elevation of the element through the shadow, so for the ::before it’s $dp_from and for the ::after it’s $dp_to</p><p>opacity: 1; a value of 1 on the ::before means this will be shown 100% while a value of 0 on the ::after means this will not be displayed yet.</p><h4>animateShadow</h4><p>This is a very simple mixin that should be quite clear.</p><pre><a href="http://twitter.com/mixin">@mixin</a> animateShadow {<br>    &amp;::before {<br>        opacity: 0;<br>    }<br>    &amp;::after {<br>        opacity: 1;<br>    }<br>}</pre><p>Its purpose is simply to inverse the opacity of the two pseudo elements that we already set up the shadows on.</p><h3>How do we use this in practice you ask?</h3><p>Simply set up the shadows on the desired element like so:</p><pre><a href="http://twitter.com/include">@include</a> animateShadowSetup(1, 8);</pre><p>That ^ just sets the initial shadow to 1dp elevation while preparing the second shadow at 8dp elevation. Then when you are ready to animate, for example on :hover, just do this:</p><pre>&amp;:hover {<br>    <a href="http://twitter.com/include">@include</a> animateShadow;<br>  }</pre><p>And that just inverts the opacity of the pseudo elements where the shadows are set. The effect is pretty good if I do say so myself.</p><p>That is it. See, not as complicated as it first seemed. Now go and have fun with it and feel free to modify it to fit your needs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bba646a06bf2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>