简体   繁体   English

Sass.js在线编译

[英]Sass.js online compilation

OK, I am a bit confused. 好吧,我有点困惑。 I've downloaded and included the sass.js files into my webpage head section: 我已经下载并包含在sass.js文件到我的网页head部分:

<script src="assets/plugins/sassjs/sass.js"></script>

This is the code I have in the body part: 这是我在body部分中的代码:

<span id="foo">This text should be green</span>

Below is the code I try to compile (placed in the head section too): 以下是我尝试编译的代码(也放置在head ):

    <script>
    // init a SAAS instance
    var sass = new Sass();

    // Example
    var scss = '$color: green; #f00 { color: $color; }';
    sass.compile(scss, function(result) {
        console.log(result);
    });
    </script>

As a result I do have the compilation result output in the console, however the styles won't apply. 结果,我确实在控制台中输出了编译结果,但是样式不适用。 Am I missing something and this is to be used with Node.js only? 我是否缺少某些内容,并且只能与Node.js一起使用? I really don't understand how this should work. 我真的不明白这应该如何工作。

You need to add <style> element and insert the result to it: 您需要添加<style>元素并将结果插入其中:

// in HTML
<style id="sass"></style>

// in JS
document.getElementById('sass').innerText = result.text;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM