admin管理员组

文章数量:1023738

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";

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";

Share Improve this question edited Jan 19, 2012 at 1:55 gdoron 150k59 gold badges302 silver badges371 bronze badges asked Jan 19, 2012 at 1:54 LanstonLanston 11.9k9 gold badges34 silver badges38 bronze badges 2
  • I just found a trick tough it's not so elegant 0px+@clientHeight – Lanston Commented Jan 19, 2012 at 2:06
  • Official documentation does have this example but they don't use the 'px' at the end.. So it's probably not needed. Is the height incorrect when you don't include 'px' at the end? Does piled CSS have the 'px' appended for this property (is this the example with space between number and px)? – bzx Commented Feb 6, 2012 at 7:44
Add a ment  | 

3 Answers 3

Reset to default 4

I know it's been quite a long time, but if you or anyone else happens to be looking for an answer still, this worked for me:

@clientHeight: unit(`$(window).height()`, px);

From the LESS function reference:

unit

Remove or change the unit of a dimension

I just found a trick tough it's not so elegant 0px+@clientHeight

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(' ', '');

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";

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";

Share Improve this question edited Jan 19, 2012 at 1:55 gdoron 150k59 gold badges302 silver badges371 bronze badges asked Jan 19, 2012 at 1:54 LanstonLanston 11.9k9 gold badges34 silver badges38 bronze badges 2
  • I just found a trick tough it's not so elegant 0px+@clientHeight – Lanston Commented Jan 19, 2012 at 2:06
  • Official documentation does have this example but they don't use the 'px' at the end.. So it's probably not needed. Is the height incorrect when you don't include 'px' at the end? Does piled CSS have the 'px' appended for this property (is this the example with space between number and px)? – bzx Commented Feb 6, 2012 at 7:44
Add a ment  | 

3 Answers 3

Reset to default 4

I know it's been quite a long time, but if you or anyone else happens to be looking for an answer still, this worked for me:

@clientHeight: unit(`$(window).height()`, px);

From the LESS function reference:

unit

Remove or change the unit of a dimension

I just found a trick tough it's not so elegant 0px+@clientHeight

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(' ', '');

本文标签: javascriptvariable manipulation in LessStack Overflow