CSS animate custom properties/variables

This can be achieved by defining variables using (as of writing this, not well-supported) @property, which allows declaring types and that allows the browser to “understand”, for example, that a certain property (variable) is a Number and then it can gradually animate/transition that variable. Example Code: @property –opacity { syntax: ‘<number>’; /* <- defined as … Read more

Can I transition the flex-grow of a flex box to produce an animation?

flex-grow is animatable but only if the value is a <number>. However it seems that Google Chrome (v41) doesn’t trigger the animation if the value is set to 0. A workaround for this could be to use a very small value instead — something like 0.0001: Updated example. $(“.item”).click(function() { $(“.item”).addClass(“collapse”); $(this).removeClass(“collapse”); }); html, body … Read more

Filling water animation

Here are four different versions to supplement @misterManSam’s brilliant answer. 1. With Easing Explanation If you filled up a circular bowl full of liquid, it would fill faster at the bottom and top than it would in the middle (because there is more area to cover in the wider middle section). So, with that crude … Read more

How to window.scrollTo() with a smooth effect

2018 Update Now you can use just window.scrollTo({ top: 0, behavior: ‘smooth’ }) to get the page scrolled with a smooth effect. const btn = document.getElementById(‘elem’); btn.addEventListener(‘click’, () => window.scrollTo({ top: 400, behavior: ‘smooth’, })); #x { height: 1000px; background: lightblue; } <div id=’x’> <button id=’elem’>Click to scroll</button> </div> Older solutions You can do something … Read more

How to add animated gradient to an svg path?

You can use the SMIL animation of SVG. The idea is to animate the color-stop or the offset of the gradient to create the needed effect: svg { border:1px solid; width:200px; } <svg xmlns=”http://www.w3.org/2000/svg” xmlns:xlink=”http://www.w3.org/1999/xlink” viewBox=”10 10 24 24″> <defs> <linearGradient id=”linear-gradient” x1=”-100%” y1=”0″ x2=”200%” y2=”0″ > <stop offset=”0″ stop-color=”red”> <animate attributeName=”offset” values=”0;0.2;0.5″ dur=”2s” repeatCount=”indefinite” … Read more