在较少使用javascript计算的值 [英] using javascript calculated values in less
问题描述
在LESS中,我使用以下代码来获取窗口的高度。
@winheight:`$(window).height )
我得到的是一个数字,但是当我添加 px
有单位,
height:@winheight px;
它会编译成类似 height:910 px
。
我试图在javascript评估之后也有单位。但我得到了相同的结果。
@winheight:`$(window).height()`px
height :@winheight;
...
height:910 px;
如何获得 height:910px
(没有数字和单位之间的空格)?
对于前四个结果,它会创建一个字符串 height:910px
,无法正确呈现。
@winheight:`$(window).height()`;
height:〜@ {winheight} px;
In LESS I used following code to get the window's height.
@winheight:`$(window).height()`
What I'm getting is a number, but when i add px
there to have the unit,
height: @winheight px;
It will compile to something like height: 910 px
.
I tried to have the unit after the javascript evaluation too. but I got the same result.
@winheight:`$(window).height()`px
height: @winheight;
...
height:910 px;
How can I get height:910px
there (without the space between number and unit) ?
EDIT:
As for the first four results, it creates a string height:"910px"
, which doesn't render correctly.
Simply use string interpolation and then escape from the string using ~
:
@winheight:`$(window).height()`;
height: ~"@{winheight}px";
这篇关于在较少使用javascript计算的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!