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

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

问题描述

尝试搜索此内容,但鉴于语法很难.有没有办法在 LESS 中生成随机数?我查看了文档并没有看到任何内容,但想知道是否有人知道技巧或未记录的解决方案.

解决方案

根据文档:><块引用>

JavaScript 评估JavaScript 表达式可以作为 .less 文件中的值进行评估.我们建议谨慎使用此功能,因为端口无法编译 LESS,这会使 LESS 更难维护.如果可能的话,试着想一个可以添加的功能来达到同样的目的,并在github上索取.我们计划允许扩展可用的默认功能.但是,如果您仍然想在 .less 中使用 JavaScript,则可以通过用反引号包裹表达式来实现:

所以这应该有效:

@var: `Math.random()`;

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.

解决方案

According to the documentation:

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:

So this should work:

@var: `Math.random()`;

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

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