可以在SASS / Compass中创建随机数吗? [英] Possible to create random numbers in SASS / Compass?
本文介绍了可以在SASS / Compass中创建随机数吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究一个使用SASS和Compass的项目,并且需要以某种方式在CSS文件中得出一些随机数。具体而言,我需要一些介于0和1之间的浮点数。
I'm working on a project where I utilize SASS and Compass and need to somehow come up with some random numbers in the CSS file. Specifically, I need some floating point numbers between 0 and 1. Is this possible with SASS and Compass alone?
推荐答案
如果您创建一个sass函数是可能的,因为sass是ruby,它就像打开function模块并注入您的随机函数一样简单
This is very possible if you create a sass function since sass is ruby its as easy as opening the functions module and injecting your random function
module Sass::Script::Functions
module MyRandom
def random
rand(1.0)
end
end
include MyRandom
end
在sass加载后需要文件
require the file after sass has loaded
然后在您的样式表
$my-randome-number: random();
这篇关于可以在SASS / Compass中创建随机数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文