DEV Community

Amelia Ruzek
Amelia Ruzek

Posted on

1 3

How to Use SASS/SCSS in the Anime.js Animation Library

Anime.js is an excellent JavaScript animation library that’s easy to use and easy to read. Documentation lists accepted values for properties as unit-less, specific unit, relative, colors, from-to, and function based. Anime.js might not accept SASS directly, but does accept JavaScript variables.

Oh! Of Course!

If a value for a CSS property in anime.js can be a simple variable, the question becomes: How to Pass SCSS into a JavaScript Variable.

Good News! There’s a package for that! css-loader


npm install --save-dev css-loader


Ok, Now What?

Export your variable directly from the .scss file using the css-loader syntax and then import your .scss into your JavaScript!


// variables.scss
$white-color: #ffffff;

:export {

whitecolor: $white-color;

}


//your js file
import variables from variables.scss

anime ({
...
color: variables.whitecolor;
...
})


And Finally
You have a JavaScript variable that can be added as a value for your css properties in your anime.js animations!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →