在LESS CSS中生成随机数? [英] Generate random number in LESS CSS?

查看:5700
本文介绍了在LESS CSS中生成随机数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试搜索,但是给定的语法很难。有没有办法在LESS中生成一个随机数?我检查了文档,没有看到任何东西,但想知道是否有人知道一个伎俩或未解决的解决方案。

Tried searching for this but it's difficult given the syntax. Is there any way to generate a random number in LESS? I checked the documentation and don't see anything, but wondered if anyone knew of a trick or undocumented solution.

推荐答案

文档


JavaScript评估
可以将JavaScript表达式计算为.less文件内的值。我们建议谨慎使用此功能,因为LESS不能由端口编译,这使得LESS难以维护。如果可能,尝试想一个可以添加以实现相同的目的,并要求在github上的函数。我们计划允许扩展可用的默认功能。但是,如果您仍然想要在.less中使用JavaScript,则可以通过将表达式换行为反转的方式来实现:

JavaScript evaluation JavaScript expressions can be evaluated as values inside .less files. We recommend using caution with this feature as the LESS will not be compilable by ports and it makes the LESS harder to maintain. If possible, try to think of a function that can be added to achieve the same purpose and ask for it on github. We have plans to allow expanding the default functions available. However, if you still want to use JavaScript in .less, this is done by wrapping the expression with back-ticks:

应该工作:

@var: `Math.random()`;

这篇关于在LESS CSS中生成随机数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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