在较少使用javascript计算的值 [英] using javascript calculated values in less

查看:116
本文介绍了在较少使用javascript计算的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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,无法正确呈现。

解决方案

只需使用字符串插值,然后〜:

从字符串中http://lesscss.org/#-escaping\">描述

  @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屋!

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