Is there a way to import variables from javascript to sass or vice versa?
You can read the sass file with a server side script, "parse" it and echo the values you need to javascript.
How to share value from js object to sass variable in react-js?
Using javascript you can not change the value of scss files because scss is compiled into css in the server and then sent to the client where the javascript is executed.
However you can achieve that via css variables (more here).
You could use css variables with a default value and then change the value of the variable via JS.
How can I use Sass variables in a JavaScript function?
Just seen this earlier this morning here: http://viget.com/extend/sharing-data-between-sass-and-javascript-with-json
First you need to include: https://github.com/vigetlabs/sass-json-vars
Install the gem:
gem install sass-json-vars
Place the variables in a json file
// variables.json
{
"font-sans": "Helvetica, sans-serif",
"colors": {
"red": "#c33"
}
}
Import the file in Sass to expose variable names:
@import "variables.json"
body {
color: map-get($colors, red);
font: $font-sans;
}
Require sass-json-vars when compiling
sass style.scss -r sass-json-vars
Related Topics
Evaluating a String as a Mathematical Expression in JavaScript
Sending Command Line Arguments to Npm Script
Jspdf Can't Get Any Styling to Work
Jquery Event That Triggers After CSS Is Loaded
How to Compare Two Color Values in Jquery/Javascript
Google Map Custom Marker with CSS Rounded Corner
Npm Not Installing Returns Error Consistently
How to Sort Strings in JavaScript
What Is the Significance of the JavaScript Constructor Property
How to Determine If a Variable Is 'Undefined' or 'Null'
Can't Access Object Property, Even Though It Shows Up in a Console Log
How to Use the Spacing Utility Classes in Bootstrap
How to Fetch the Value of a Non-Standard CSS Property via JavaScript
Fullpage.Js. Adding a Scroll Delay
Repeat Animation Every 3 Seconds
Divide Semi Circle with Stroke-Dasharray and on Active Color Fill