I'm new to keyframe animations and after some searching this article seemed like a good place to start.
Here is the articles code in codepen - http://codepen.io/anon/pen/yYPxJM
@mixin keyframes($animation-name) {
@-webkit-keyframes $animation-name {
@content;
}
@-moz-keyframes $animation-name {
@content;
}
@-ms-keyframes $animation-name {
@content;
}
@-o-keyframes $animation-name {
@content;
}
@keyframes $animation-name {
@content;
}
}
@mixin animation($str) {
-webkit-animation: #{$str};
-moz-animation: #{$str};
-ms-animation: #{$str};
-o-animation: #{$str};
animation: #{$str};
}
@include keyframes(slide-down) {
0% { opacity: 1; }
90% { opacity: 0; }
}
.element {
width: 100px;
height: 100px;
background: black;
@include animation('slide-down 5s 3');
}
However, it doesn't work "as is" and I'm not sure how to proceed.
I'm going to be animating objects as I scroll down the page. For example animating the some to fade-in, others to scale (call to action) to make them pop. The jQuery shouldn't be an issue, it's these animations that are causing me the issues.
Would love some help to understand what I'm failing to do right.
Thanks in advance!
So, how to add @keyframes animation code in SCSS? It is essential to use the syntax and rules as mentioned in SCSS. Firstly, create a @mixin for animation that includes the animation properties as arguments. It will make it easier for a developer to include this @mixin for different elements.
Even if you've assigned a keyframes rule to an element, it still may not appear to play if you haven't set an animation-duration. By default, a CSS animation cycle is zero seconds long. To override this, add an animation-duration rule to your targeted element with a seconds value, in the same block as animation-name.
The @keyframes rule specifies the animation code. The animation is created by gradually changing from one set of CSS styles to another. During the animation, you can change the set of CSS styles many times.
Each keyframe describes how the animated element should render at a given time during the animation sequence. Since the timing of the animation is defined in the CSS style that configures the animation, keyframes use a <percentage> to indicate the time during the animation sequence at which they take place.
You have to use Interpolation: #{}, so your $animation-name
is not treated as CSS.
Here's my favorite article on the matter: All You Ever Need to Know About Sass Interpolation
Please, have a look at the code:
@mixin keyframes($animation-name) {
@-webkit-keyframes #{$animation-name} {
@content;
}
@-moz-keyframes #{$animation-name} {
@content;
}
@-ms-keyframes #{$animation-name} {
@content;
}
@-o-keyframes #{$animation-name} {
@content;
}
@keyframes #{$animation-name} {
@content;
}
}
@mixin animation($str) {
-webkit-animation: #{$str};
-moz-animation: #{$str};
-ms-animation: #{$str};
-o-animation: #{$str};
animation: #{$str};
}
@include keyframes(slide-down) {
0% { opacity: 1; }
90% { opacity: 0; }
}
.element {
width: 100px;
height: 100px;
background: black;
@include animation('slide-down 5s 3');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With