在Less中的可变操作 [英] variable manipulation in Less

查看:84
本文介绍了在Less中的可变操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部

我想计算页面的高度,并在我的 test.less


$ b当我使用时,$ b

 @clientHeight:`$(window).height()`; 

@clientHeight ,因为jquery只返回一个数字,我需要加上 px

这样的单位方式:

1)

 div {height:@ clientHeight + px; 


b $ b

它出来了:

height:705 px;
(注意,它们之间有一个空格) >
2)

 @clientHeight:`$(window).height()+'px'` 

它出来了:

height:705px;

 尝试此操作以修剪从返回的高度值中删除空格的操作:class =h2_lin> > @clientHeight:`$ .trim($(window).height())+'px'` 

(或者如果不以这种方式处理,不能测试它。)



..或使用纯文本 str.replace('','');


all
I want to calculate the height of the page ,and in my test.less

@clientHeight:`$(window).height()`;

when I use the @clientHeight,as jquery return just a number,I need to plus the unit like px
So,I tried these ways:
1)

div{height: @clientHeight+px;

It came out :
height: 705 px; (Note that there's a space between them)
2)

@clientHeight:`$(window).height()+'px'`

It came out :
height: "705px";

解决方案

Try this to trim off whitespace from the returned height value:

@clientHeight: `$.trim( $(window).height() ) + 'px'`;

(or dissect this if it won't be processed this way, sorry not using less.js, can't test it).

..or use plain str.replace(' ', '');

这篇关于在Less中的可变操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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