npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kf-animate

v1.0.3

Published

A powerful sass mixin for generating keyframe css animations

Downloads

3

Readme

kf-animate

A powerful sass mixin for generating keyframe css animations

##Contents

##Installation

npm install kf-animate --save

Then in your main scss file (making sure the path is correct)

@import '../node_modules/kf-animate/kf-animate';

I also recommend using Autoprefixer in combination with this mixin for optimal browser support.

##Basic Usage

Here is an example of how to do a simple animation of something fading in and out continuously (also the text is changing color).

//A simple SASS keyframe animation
.element {
    $fadeInOut:
        0% (opacity: 0, color: red),
        80% (opacity: 1, color: blue),
        100% (opacity: 0, color: red),
    ;
    @include kf-animate(fadeInOut, $fadeInOut);
}
/*CSS output*/
@keyframes fadeInOut {
    0% { opacity: 0; color: red; }
    80% { opacity: 1; color: blue; }
    100% { opacity: 0; color: red; }
}
.element {
    animation: fadeInOut 1s infinite linear both;
}

##Auto generated keyframes

It can get really tedious having to figure out what all the keyframe percentages need to be, especially if you just want them all to be evenly spaced and there's like 8 of them or something.

Well guess what! kf-animate is able to take away all that pain and figure out the key frames for you! As long as you are happy with the keyframes all being evenly spaced, this is a perfectly fine way of writting your SASS animation code:

//Let kf-animate calculate the keyframes for you!

.element {
    $fadeInOut:
        (opacity: 0, color: red),
        (opacity: 1, color: blue),
        (opacity: 0, color: red),
    ;
    @include kf-animate(fadeInOut, $fadeInOut);
}
/*CSS output*/
@keyframes fadeInOut {
    0% { opacity: 0; color: red; }
    50% { opacity: 1; color: blue; }
    100% { opacity: 0; color: red; }
}
.element {
    animation: fadeInOut 1s infinite linear both;
}

##Animation settings

If you want to maybe have a slow fade in while the background changes colors, you can do this:

//only animate the attributes you want to

.element {
    $fadeInOut:
        (background: red, opacity: 0),
        (background: blue),
        (background: green),
        (background: yellow),
        (background: orange),
        (background: grey),
        (background: black),
        (background: white, opacity: 1),
    ;
    @include kf-animate(fadeInOut, $fadeInOut, 1s, 1);
}

If you are wondering what that 1 at the end is, it's the number of loops the animation will play for. Most of the time you will want this to be either 1 or infinite, it defaults to infinite.

This is the order that the kf-animate attributes go in and their default settings:

@include kf-animate($name, $keyframes, $timing: 1s, $loops: infinite, $ease: linear, $fill: both)

$timing is used for both duration and delay. Duration is always the first value and if you add a second value to the $timing variable it will be the delay.

If you are wondering what the $fill variable is, it's the animation-fill-mode property. If you're still confused, have a read of this excellent article: Understanding the CSS animation-fill-mode Property. You shouldn't need to worry about this setting too much though. The default should work well in 99% of circumstances.

##Predefined keyframe animations

Ok, now for another scenario. What if we want to apply the same effect to a range of different elements, possibly even with different timings? If we used the kf-animate mixin to do this, yes it would work but we'd also have a whole heap of duplicated css in our output file. What we really want to be able to do is state the keyframes once but refer back to it multiple times with different timings. This is when the kf-definition and kf-predefined mixins come in handy.

//define a set of keyframes and then refer back to it multiple times with different timings

.parent {
    &__child {
        $fadeInOut:
            (opacity: 0),
            (opacity: 1),
            (opacity: 0),
        ;
        @include kf-definition(fadeInOut, $fadeInOut);
        &--anim1 {
            @include kf-predefined(fadeInOut, 1s);
        }
        &--anim2 {
            //anim2 starts the same animation 0.5s after anim1
            @include kf-predefined(fadeInOut, 1s 0.5s);
        }
    }
}
/*CSS output*/
@keyframes fadeInOut {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}
.parent__child--anim1 {
    animation: fadeInOut 1s infinite linear both;
}
.parent__child--anim2 {
    animation: fadeInOut 1s 0.5s infinite linear both;
}

The variables for kf-definition are simply the animation name, followed by the animation set.

The variables for kf-predefined are the same as kf-animate except without the $keyframes variable.

//The variables

@include kf-definition($name, $keyframes);

@include kf-predefined($name, $timing: 1s, $loops: infinite, $ease: linear, $fill: both);