有没有办法从javascript导入变量到sass或反之亦然? [英] Is there a way to import variables from javascript to sass or vice versa?

查看:123
本文介绍了有没有办法从javascript导入变量到sass或反之亦然?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个依赖于块概念的css网格系统。所以我有一个基本文件,如:

I am making a css grid system that relies on the concept of blocks. So I have a base file like:

$max-columns: 4;
$block-width: 220px;
$block-height: 150px;
$block-margin: 10px;

它由mixin使用:

@mixin block ($rows, $columns, $max-columns) {
  display: block;
  float: left;
  margin: $block-margin 0 0 $block-margin;
  box-sizing: border-box;
  width: ($block-width * $columns) - $block-margin;
}

但我还想让javascript访问基础中的变量文件。我想我可以做一个看不见的div,并给它$ block-width,$ block-height和$ block-margin属性,并从那里拉取值。但是最大列,不直接映射到任何东西,所以我必须想出一个hacky的方式来渲染它在一个div。

But I'd also like javascript to have access to the variables in the base file. I was thinking that I could make an invisible div, and give it the $block-width, $block-height, and $block-margin attributes and pull the values from there. But max-columns, doesn't map to anything directly, so I'd have to come up with a hacky way to render it in a div. Is there a cleaner way to share values from sass/css to javascript or vice versa?

推荐答案

您可以读取sass文件与sass / css,一个服务器端脚本,解析它,并回显你需要的javascript的值。

You can read the sass file with a server side script, "parse" it and echo the values you need to javascript.

这篇关于有没有办法从javascript导入变量到sass或反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆