<?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 gradinariu bogdan on Medium]]></title>
        <description><![CDATA[Stories by gradinariu bogdan on Medium]]></description>
        <link>https://medium.com/@gion_13?source=rss-cb3bfbd3a90e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wrVYxfA6z4HC_1ch.jpeg</url>
            <title>Stories by gradinariu bogdan on Medium</title>
            <link>https://medium.com/@gion_13?source=rss-cb3bfbd3a90e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 01:34:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gion_13/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[React + d3 = ?]]></title>
            <link>https://medium.com/@gion_13/react-d3-ea83b7dc8c5d?source=rss-cb3bfbd3a90e------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea83b7dc8c5d</guid>
            <category><![CDATA[charts]]></category>
            <category><![CDATA[javascript-frameworks]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[d3js]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[gradinariu bogdan]]></dc:creator>
            <pubDate>Thu, 27 Feb 2020 14:40:51 GMT</pubDate>
            <atom:updated>2020-02-27T14:40:51.145Z</atom:updated>
            <content:encoded><![CDATA[<h3>React + d3 = ?</h3><p>Both React and d3 are big names in web development and have proven to be among the best frontend libraries to use when creating a web app. React is one of the most popular javascript libraries for building user interfaces, while d3 is one of the most appreciated front-end libraries for creating stunning data driven visualisations. However, working with both of them at the same time isn’t straight forward and can easily get confusing.</p><p>I recently had to build a bubble chart and integrate it into an existing React application. As I had some prior experience with d3, I went on using d3 and React for the job.</p><h3>The problem</h3><p>One of my first questions was: Who will manipulate the DOM? Who will manage the app state?</p><figure><img alt="https://macwright.org/2016/10/11/d3-and-react.html" src="https://cdn-images-1.medium.com/max/541/1*KGSFgup8bOqM6fvqxClamg.png" /><figcaption><a href="https://macwright.org/2016/10/11/d3-and-react.html">https://macwright.org/2016/10/11/d3-and-react.html</a></figcaption></figure><p>Since both libraries do a great job at manipulating the DOM, when building a React+d3 component, there needs to be a tradeoff:</p><p>You can use React as a simple wrapper that instantiates some standalone d3 visualisations, while d3 does most of the work:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*Wt4dJ4ugTMLWSO2mGVnjMg.png" /></figure><p>Another approach is to give React the ownership of the DOM and rely on d3 for the heavy math stuff:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*UmO93XmHDnClA1xK8xpR_w.png" /></figure><p>There are plenty of<a href="https://www.google.com/search?q=d3+with+react"> articles on this topic</a> (some <a href="https://macwright.org/2016/10/11/d3-and-react.html">older</a>, some <a href="https://daniellecloss.github.io/react-d3-dom-slidedeck/">newer</a>) and, while the opinions are divided, I got the impression that letting React handle rendering would be a better approach.</p><p>There are even great collections of components written this way, and my favourite is by far <a href="https://vx-demo.now.sh/">https://vx-demo.now.sh</a>.</p><h3>Letting React handle the DOM</h3><p>So I started to build my bubble chart component as a react component that renders some SVG:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cac5fad3ed7a2f3c75faa8dbcbac4adb/href">https://medium.com/media/cac5fad3ed7a2f3c75faa8dbcbac4adb/href</a></iframe><p>That is pretty straight forward: there’s a React component that’s rendering an SVG with multiple circles, and with React, you can easily manage the style, position and hover/clicked state of each circle.</p><p>The thing with this bubble chart was that I had no information on how to plot the bubbles. There were no specs on how to map each circle on a fixed cartesian point (x, y).<br>So I needed an algorithm to place the bubbles on the screen in a meaningful way in order to make some sense out of the visualisation.</p><p>This is where <a href="https://github.com/d3/d3-force">d3’s force layout</a> kicked in:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0388fd5663a52308a7052d6ed4130944/href">https://medium.com/media/0388fd5663a52308a7052d6ed4130944/href</a></iframe><p>What I did was to setup a d3 force simulation that would give each circle a unique position.</p><p>If you’re not familiar with it, the simulation is ultimately an event emitter that emits a <em>tick</em> event with the updated positions of the nodes. After it’s setup, you can just listen to that event and update all the rendered bubbles.</p><p>I won’t go into depth on this functionality, but will just note that for me, this was one of the selling points of using d3 in the first place, since you can do awesome animations using this module, such as centring items, adding gravity, managing collision and many others.</p><p>This solution worked as a charm on a small dataset. But it didn’t scale. When rendering more items, the result was a staggering animation of circles that are constantly updating their position:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*KqS5uZS9ZXvbSrs0Z8dkrQ.gif" /></figure><p>You can see it in action here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fu6s85&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fu6s85&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2Fu6s85%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7ed35ca7ec0ae383001e926dfbc107d/href">https://medium.com/media/a7ed35ca7ec0ae383001e926dfbc107d/href</a></iframe><p>I then decided to only use the last position of the force simulation (and not having to constantly update the intermediary steps) and add a simple tween to each circle using a <a href="https://www.react-spring.io/">react-spring</a> — a lightweight react animation library.</p><p>Setting up react-spring to handle animations was the easy part. Forcing the simulation to end in order to get the last positions proved to be a bit tricky.</p><p>D3’s simulation isn’t a timeline based animation (as <a href="https://greensock.com/gsap/">greensock</a> is), so there’s no way to force it to complete unless all the intermediary steps are completed. <br>So I ended up manually iterating through each tick of the simulation in order to force it to finish (a technique described by Mike Bostock — the creator of d3 — as “static force layout” in <a href="https://bl.ocks.org/mbostock/1667139).">https://bl.ocks.org/mbostock/1667139).</a> After that I would update all the circle positions in one single smooth animation:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Fqws3c&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Fqws3c&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/c36e43d79f60a394f089f0c04e70f9a4/href">https://medium.com/media/c36e43d79f60a394f089f0c04e70f9a4/href</a></iframe><p>This solution works great and there’s no staggering animation 🎉.</p><p>The only downside is that with larger datasets, the simulation can take too much time to update, leaving you with several “frozen screen” situations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*laZRon5hMEag0tvNqBQQTg.gif" /></figure><p>That’s when I thought I would try the other approach and let d3 handle both math, rendering and animation.</p><h3>Giving d3 the ownership of the DOM</h3><p>By letting d3 handle most of the logic, this means that React would only serve as a wrapper component that initiates a d3 function with its props and a DOM element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/289bd545c8c9c8454db03fa2680ceab0/href">https://medium.com/media/289bd545c8c9c8454db03fa2680ceab0/href</a></iframe><p>Once that is setup, we need to dive a bit more in d3. Since d3 handles all the rendering, you should get familiar with the way d3 handles updates. Here’s one article that I think does a good job at explaining d3’s enter-update-exit pattern: <a href="http://bl.ocks.org/alansmithy/e984477a741bc56db5a5">http://bl.ocks.org/alansmithy/e984477a741bc56db5a5</a></p><p>Here’s my take on a simple d3 bubble chart implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/58d13b7927f9e9f56845dc0ee212092d/href">https://medium.com/media/58d13b7927f9e9f56845dc0ee212092d/href</a></iframe><p>What’s left now is to hook React and d3 together and make sure that react informs d3 of any updates.</p><p>You can notice that we fixed the <em>frozen screen</em> issue from the initial approach so that the chart reacts and renders the new data as soon as the props change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-y8TKws-NP2G4c6GB9J94Q.gif" /></figure><h3>Conclusion</h3><p>Integrating React with d3 can have a lot of advantages, but it’s important to clearly separate who is doing what, according to what each does best.</p><p>With most DOM manipulations, you should let React handle it, like storing data or passing it to components. But when it comes to highly complex data visualisation calculations that need to scale, leave that it d3.</p><p>I can’t say which of the implementations is better, because you have to take into consideration many things, like the use case that you’re building the component for, which approach is easier to understand, maintain and extend and, of course, which one performs better.</p><p>I’ve put both implementations side by side in the following playground so you can see, tweak and decide for yourself which one is for you:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2F7i1i2&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2F7i1i2&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F7i1i2%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fab09b7a9cc1640f92fa7d3f79e8235/href">https://medium.com/media/2fab09b7a9cc1640f92fa7d3f79e8235/href</a></iframe><p>After this experience, for me React+d3 = ❤️.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea83b7dc8c5d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inspect the uninspectable]]></title>
            <link>https://medium.com/@gion_13/inspect-the-uninspectable-45b3d1002ecd?source=rss-cb3bfbd3a90e------2</link>
            <guid isPermaLink="false">https://medium.com/p/45b3d1002ecd</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[debugger]]></category>
            <dc:creator><![CDATA[gradinariu bogdan]]></dc:creator>
            <pubDate>Mon, 24 Feb 2020 22:54:11 GMT</pubDate>
            <atom:updated>2020-02-24T22:57:11.541Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CtwOjDqA-Zcx22xxK0XX8g.png" /></figure><p>As a frontend developer you often rely on using the dev tools to inspect elements in order to debug or tweak things.<br>However, there are cases where you just can’t seem to inspect a certain element on the screen. That’s something that drove me mad initially and I’m going to show you how I solved this issue.</p><p>With more and more websites written in <a href="https://reactjs.org/">React</a> or other libraries that use virtual DOM, you usually end up having elements that are conditionally rendered on the screen:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60fbd8c7f8e5191280c0d47d77d995ef/href">https://medium.com/media/60fbd8c7f8e5191280c0d47d77d995ef/href</a></iframe><p>Back in the <a href="https://angularjs.org/">angular.js</a> era, you probably would’ve always render all the elements and just toggle their visibility via css styles/classes. But this is more performant and easier to understand.</p><p>My pain comes from elements that are rendered only when certain UI states are triggered. Take a tooltip component for example: it should render a message only when a trigger element is hovered. The same thing happens to an autocomplete dropdown. It should only be rendered while the targeted input is focused.</p><p>Here’s a simple search autosuggestion component that shows what I’m talking about:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60d3af773d5abc4d7713ca69975464d3/href">https://medium.com/media/60d3af773d5abc4d7713ca69975464d3/href</a></iframe><p>The suggestion element is only shown when the input is focused. If you try to inspect the suggestion DOM element, then the input loses focus and the suggestion element disappears :(</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7B8EZAO_5SHIqHoQXW0eZw.gif" /></figure><p>You can try it yourself here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodesandbox.io%2Fembed%2Flucid-dan-8m45k&amp;display_name=CodeSandbox&amp;url=https%3A%2F%2Fcodesandbox.io%2Fs%2Flucid-dan-8m45k&amp;image=https%3A%2F%2Fcodesandbox.io%2Fapi%2Fv1%2Fsandboxes%2F8m45k%2Fscreenshot.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codesandbox" width="1000" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/0457d39892756c177fa91f4028cd588e/href">https://medium.com/media/0457d39892756c177fa91f4028cd588e/href</a></iframe><p>quite frustrating, huh?</p><p>My solution was to programatically stop the script execution (with a simple debugger statement) when the element is visible, so that the logic that hides the element couldn’t be triggered.</p><p>This can be done just by pasting the following snippet in the dev tools console: setTimeout(() =&gt; {debugger;}, 2000)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2s-jZaZL9JdqlBm5UkqQ3Q.gif" /></figure><p>This simple hack was the solution to inspect any element that gets hidden or removed from the DOM when you try to… well, inspect them :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45b3d1002ecd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS only image slideshow for your website]]></title>
            <link>https://medium.com/@gion_13/css-only-slideshow-98967e2ce80c?source=rss-cb3bfbd3a90e------2</link>
            <guid isPermaLink="false">https://medium.com/p/98967e2ce80c</guid>
            <category><![CDATA[sideshow]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[image]]></category>
            <dc:creator><![CDATA[gradinariu bogdan]]></dc:creator>
            <pubDate>Tue, 20 Dec 2016 10:57:38 GMT</pubDate>
            <atom:updated>2016-12-20T12:37:50.588Z</atom:updated>
            <content:encoded><![CDATA[<p>I know that this topic might not be as hot as other cutting edge technological breakthroughs that alters the today’s front-end world (such as ES6, CSS4 or any other new features), but I want to share my experience on creating a css slideshow without altering any DOM or writing any JS.</p><h3>TL;DR.</h3><p>Here’s what I ended up using as a css image slideshow on my site: <a href="http://codepen.io/gion/full/MbLVZR/">http://codepen.io/gion/full/MbLVZR/</a></p><p>Continue reading for the <strong>how</strong> and <strong>why</strong>.</p><h3>Why</h3><p>I thought that adding <strong>a simple image slideshow</strong> in my website would be a trivial job, I started googling for “<em>web image slideshow</em>” and, as expected, my screen was flooded with <a href="https://www.google.com/search?q=web+image+slideshow">lots of results</a> that either pointed me to jQuery slider plugins or tutorials on how to build your own javascript based image slideshow.</p><p>Since I didn’t want to add other JS dependencies and/or drastically alter the HTML structure of my existing site, I refined the search to “<em>css only slideshow</em>” or similar queries. Unfortunately, that didn’t help and I was stuck with either adding some 3rd party slider libraries or altering my markup to include all the images that would magically be animated with CSS.</p><p>And I went with the secret option #3: write my own CSS image slideshow that doesn’t rely on any JS and does not alter the HTML markup.</p><h3>How</h3><h4>1. I don’t want any other JS/HTML</h4><p>Ok, no JS means that we only need CSS for displaying, styling and animating the images. That’s something that any intermediate front end developer should be able to do with some help from google. But no HTML?</p><p>I originally thought I could go away with only using multiple background images on an element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/1*yJhc0GW1ZUFIuyTXe5D1_A.png" /></figure><p>And here’s my first take:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgion%2Fembed%2Fpreview%2FpNwwzj%3Fheight%3D600%26amp%3Bslug-hash%3DpNwwzj%26amp%3Bdefault-tabs%3Dcss%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fgion%2Fpen%2FpNwwzj%3Feditors%3D1100&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F6720.pNwwzj.small.a319fdfd-cc61-459a-b12e-241c93aaaf14.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/adca0591c4d27a41e3970aeb630c972a/href">https://medium.com/media/adca0591c4d27a41e3970aeb630c972a/href</a></iframe><p>Pretty neat and simple for this simple use case where you want the images to slide. This means that the pictures couldn’t crossfade :(</p><h4>2. Pseudo elements to the rescue!</h4><p>Because I needed to animate the images independently (fade/zoom/translate) and not just rely on animating the background position, I actually needed 2 image containers which translates to 2 DOM elements. Luckily we now about <em>:before</em> and <em>:after </em>pseudo elements and can use a single DOM node to represent at least 2 different things:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*PykERReATL8siGVQKXfvsw.png" /><figcaption>pseudo elements</figcaption></figure><p>Here’s the previous example pumped up with the power of pseudo elements:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgion%2Fembed%2Fpreview%2FxRQjYj%3Fheight%3D600%26amp%3Bslug-hash%3DxRQjYj%26amp%3Bdefault-tabs%3Dcss%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fgion%2Fpen%2FxRQjYj%3Feditors%3D1100&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F6720.xRQjYj.small.e8139217-aba1-4bf5-832e-70aed72189c1.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/67f8f3391e1f30c24edb814e61e2712b/href">https://medium.com/media/67f8f3391e1f30c24edb814e61e2712b/href</a></iframe><p>This is great, but I still wanted more than 2 images :(</p><h4>3. Pseudo elements with changing images</h4><p>I decided to go with the pseudo elements for displaying images and just swap images on each animation step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lHnAUiYRr-QWeHDcFs7o4w.png" /></figure><p>This way, I can animate seamlessly between the 2 layers (<em>:before</em> and <em>:after</em>) and while one of them is active, I can swap the image on the other so I can have more than 2 images.</p><p>Since I want to control these animations from CSS, I’m going to use CSS animations for the slide change effect &amp; logic:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgion%2Fembed%2Fpreview%2FpNGpom%3Fheight%3D600%26amp%3Bslug-hash%3DpNGpom%26amp%3Bdefault-tabs%3Dcss%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fgion%2Fpen%2FpNGpom%3Feditors%3D0100&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F6720.pNGpom.small.7e29d8fd-4d06-4fa3-bdaf-1ab95a6bc565.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/63498645a0f8766a95b7f85e291d5069/href">https://medium.com/media/63498645a0f8766a95b7f85e291d5069/href</a></iframe><p>This is great… but not quite :(</p><p>Aside of the fact that there are still some glitches that can maybe be tweaked, if you’re running the above example in Firefox, you might not see anything. This is because the <em>background-image </em>property is not animatable ( <a href="https://www.w3.org/TR/css3-transitions/#animatable-properties">as stated in the specs</a>), even though webkit based browsers seem to support it.</p><h4>4. Multiple background images on pseudo elements</h4><p>I needed to reconsider multiple backgrounds and push the slideshow forward to have multiple images <em>:before</em> and <em>:after </em>the targeted element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qcfSdnywqtITS-35fVHTKw.png" /></figure><p>Combining the 2 previous steps, I ended up with this:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fcodepen.io%2Fgion%2Fpen%2FZBmRQx&amp;src=https%3A%2F%2Fcodepen.io%2Fgion%2Fembed%2Fpreview%2FZBmRQx%3Fheight%3D600%26amp%3Bslug-hash%3DZBmRQx%26amp%3Bdefault-tabs%3Dcss%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c79fa316178eaa187e24e8644fe6d21/href">https://medium.com/media/5c79fa316178eaa187e24e8644fe6d21/href</a></iframe><p>The above example works because that the transition only targets <em>opacity </em>in order to avoid image flickers while changing the steps. The challenge now is to implement it with css animations and lose the html/js helpers in the demo.</p><p>First of all, I defined the keyframes that fade in/out each one of the background images by animating the opacity.</p><p>In order to reuse the same animation for both pseudo elements, I added a delay to the second one so that when the first animation is fading out the image, the second animation should fade it in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mhIJyHfTgrpyP1nzV421jQ.png" /></figure><p>I realised that if I can’t animate the <em>background-image</em>,<em> </em>I can get things done by animating other background properties such as <em>background-size. </em>But with animations every style change gets animated… even the <em>background-size </em>that should just instantly change the image.</p><p>To get around this issue, I added a short extra step in the animation that only change the <em>background-size </em>after the image is not visible.</p><p>And, in order to spice things up, I animated some other props to enhance the slideshow effects.</p><p>And the result… [drumrolls]:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgion%2Fembed%2Fpreview%2FMbLVZR%3Fheight%3D600%26amp%3Bslug-hash%3DMbLVZR%26amp%3Bdefault-tabs%3Dcss%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fgion%2Fpen%2FMbLVZR%3Feditors%3D0100&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F6720.MbLVZR.small.9fc66de3-261d-4a0c-a582-9f79bc873327.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/c76c6722ac381b0ebad6fc0edc6ef1a2/href">https://medium.com/media/c76c6722ac381b0ebad6fc0edc6ef1a2/href</a></iframe><p>Well, that’s it for my approach on generating a pure CSS image slideshow. It works cross browser and can be used as a full background image slideshow. The CSS can get complicated, but if you’re using a preprocessor, things can get pretty easy with some mixins.</p><p>Have an opinion? Feel free to comment &amp; share.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98967e2ce80c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>