| Page 1 of 1 | [ 5 posts ] |
|
Is it possible to do something like:
var node = Y.one('#myNode'); var width = node.getStyle('width'); // return 10px var newWidth = width + 10; // return 10px10 Where the result is '10px10' I would like it to be '20px'. Is there any solution. Thanks in advance. |
|
Code: var node = Y.one('#myNode'); var width = parseInt(node.getStyle('width'), 10); // return 10 var newWidth = width + 10; // return 20 |
|
If you want the actual rendered width (which also includes borders and padding by default) as opposed to the style.width, you can get the offsetWidth, which is a number in pixels without the units:
Code: var width = node.get('offsetWidth'); var newWidth = width + 10; Also, be aware that getStyle() may return a value in units other than pixels: Code: node.setStyle('width', '40%'); var width = node.getStyle('width'); // 40% To guarantee pixel units for width, use getComputedStyle(): Code: node.setStyle('width', '40%'); var width = node.getComputedStyle('width'); // style width converted to pixels |
|
First of all its an honor to have a question answered by you YUI developers, its very nice to see videos from you and receive help on the forums from you. Thank you all for helping thats exactly what I needed.
|
Djalma Araujo
|
Hi guys, this solution with parseInt() may broken on IE? Because on IE, sems that getComputedStyle doesn't return always in pixels!
YUI solve this on method implementation? |
| Page 1 of 1 | [ 5 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group