-
25 Jan 2008 3:52 PM #1
[2.0.1][OPEN] setStyle with float
[2.0.1][OPEN] setStyle with float
This is a bump of an old thread raised on 1.x [1] - it still applies to 2.0.1
There is no special handling for 'float' within 'setStyle'.
el.setStyle('float', 'left'); // doesn't work
el.setStyle('cssFloat', 'left'); // works in standards compliant browsers
el.setStyle('styleFloat', 'left'); // works in IE
Perhaps not strictly a bug, but I'm not allowed to post in the 'feature requests' section :(
[1] http://extjs.com/forum/showthread.ph...setStyle+float
-
26 Jan 2008 10:57 AM #2
We'll take a look at this.
Aaron Conran
@aconran
Sencha Architect Development Team
-
11 May 2008 5:22 AM #3
Can this be looked at again?
Ext normalizes the opacity setting to handle browser quirks, it shojld also normalize setting of float in a cross browser manner.
This is a unique case because of two intersecting problems.
Firstly, IE is non-standard, and uses 'styleFloat', and secondly, the standard Javascript style name does not match the CSS style name. We're supposed to use 'cssFloat'
Usually, the CSS style name is just camelcased to create the Javascript style name, but 'float' appears to be disallowed (perhaps conflicting with planned datatypes)
But for total consistency, the method should be
Code:setStyle : function(prop, value){ if(typeof prop == "string"){ var camel; if(!(camel = propCache[prop])){ camel = propCache[prop] = prop.replace(camelRe, camelFn); } if(camel == 'opacity') { this.setOpacity(value); }else{ if (camel == 'float') { camel = Ext.isIE ? 'styleFloat' : 'cssFloat'; } this.dom.style[camel] = value; } }else{ for(var style in prop){ if(typeof prop[style] != "function"){ this.setStyle(style, prop[style]); } } } return this; }Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
14 May 2008 12:59 AM #4
The silly thing is that Ext.Element::getStyle does do this normalization of 'float', while setStyle doesn't!
Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
14 May 2008 1:18 AM #5
Yeah, I was just looking at this the other day and saw that getStyle does include that check. This must have just been an oversight -- we'll get it fixed shortly. Thanks for the patch.
-
14 May 2008 10:14 PM #6
Using 'float' (the string) is not a good solution. It will break in various standard scenarios (e.g. setting styles from in hash object in IE).
The other issue, is setStyle is called pretty frequently. I would really hate to add an additional conditional for a style that will be set using setStyle 1 out of 1,000,000,000 times setStyle is called. :/
-
5 Jan 2009 12:05 AM #7Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 44
Bump - This has come up again.
@Jack: If you're so concerned about setStyle overhead, why not move the code to the propCache, so it is only executed once?
Code:Ext.override(Ext.Element, { setStyle : function(prop, value){ if(typeof prop == "string"){ var camel; if(!(camel = propCache[prop])){ camel = prop.replace(camelRe, camelFn); if(camel == 'float'){ camel = Ext.isIE ? 'styleFloat' : 'cssFloat'; } propCache[prop] = camel; } if(camel == 'opacity') { this.setOpacity(value); }else{ this.dom.style[camel] = value; } }else{ for(var style in prop){ if(typeof prop[style] != "function"){ this.setStyle(style, prop[style]); } } } return this; } });
-
5 Jan 2009 5:22 PM #8
I'll have to check this with Jack, you can set float using an object hash, I'm not sure what other conditions will cause this to break though:
RE: the performance issue, we could add a setFloat method, similar to setOpacity. As Jack suggested, the extra check in setStyle would be a redundant most of the time and it does get called a lot.Code:Ext.get('foo').setStyle({ float: 'left' //no errors, IE6/IE7 });Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
6 Apr 2011 11:35 AM #9
It doesn't work with IE8 or IE9. If I use
Code:element.setStyle('styleFloat', 'right'); // works only in IE element.setStyle( {float: 'right'}); // works only in FF/Chrome element.setStyle('float', right'); // works only in FF/Chrome
The only way I've found to make it work consistently is to call setStyle twice on the element.



Reply With Quote