@@ -203,6 +203,58 @@ test( "css() explicit and relative values", 29, function() {
203203 equal ( $elem . css ( "opacity" ) , "1" , "'+=0.5' on opacity (params)" ) ;
204204} ) ;
205205
206+ test ( "css() non-px relative values (gh-1711)" , 17 , function ( ) {
207+ var cssCurrent ,
208+ units = { } ,
209+ $child = jQuery ( "#nothiddendivchild" ) ,
210+ add = function ( prop , val , unit ) {
211+ var str = ( val < 0 ? "-=" : "+=" ) + Math . abs ( val ) + unit ;
212+ $child . css ( prop , str ) ;
213+ equal (
214+ Math . round ( parseFloat ( $child . css ( prop ) ) ) ,
215+ Math . round ( cssCurrent += val * units [ prop ] [ unit ] ) ,
216+ prop + ": '" + str + "'"
217+ ) ;
218+ } ,
219+ getUnits = function ( prop ) {
220+ units [ prop ] = {
221+ "px" : 1 ,
222+ "em" : parseFloat ( $child . css ( prop , "100em" ) . css ( prop ) ) / 100 ,
223+ "pt" : parseFloat ( $child . css ( prop , "100pt" ) . css ( prop ) ) / 100 ,
224+ "pc" : parseFloat ( $child . css ( prop , "100pc" ) . css ( prop ) ) / 100 ,
225+ "cm" : parseFloat ( $child . css ( prop , "100cm" ) . css ( prop ) ) / 100 ,
226+ "mm" : parseFloat ( $child . css ( prop , "100mm" ) . css ( prop ) ) / 100 ,
227+ "%" : parseFloat ( $child . css ( prop , "100%" ) . css ( prop ) ) / 100
228+ } ;
229+ } ;
230+
231+ jQuery ( "#nothiddendiv" ) . css ( { height : 1 , padding : 0 , width : 400 } ) ;
232+ $child . css ( { height : 1 , padding : 0 } ) ;
233+
234+ getUnits ( "width" ) ;
235+ cssCurrent = parseFloat ( $child . css ( "width" , "50%" ) . css ( "width" ) ) ;
236+ add ( "width" , 25 , "%" ) ;
237+ add ( "width" , - 50 , "%" ) ;
238+ add ( "width" , 10 , "em" ) ;
239+ add ( "width" , 10 , "pt" ) ;
240+ add ( "width" , - 2.3 , "pt" ) ;
241+ add ( "width" , 5 , "pc" ) ;
242+ add ( "width" , - 5 , "em" ) ;
243+ add ( "width" , + 2 , "cm" ) ;
244+ add ( "width" , - 15 , "mm" ) ;
245+ add ( "width" , 21 , "px" ) ;
246+
247+ getUnits ( "lineHeight" ) ;
248+ cssCurrent = parseFloat ( $child . css ( "lineHeight" , "1em" ) . css ( "lineHeight" ) ) ;
249+ add ( "lineHeight" , 2 , "em" ) ;
250+ add ( "lineHeight" , - 10 , "px" ) ;
251+ add ( "lineHeight" , 20 , "pt" ) ;
252+ add ( "lineHeight" , 30 , "pc" ) ;
253+ add ( "lineHeight" , 1 , "cm" ) ;
254+ add ( "lineHeight" , - 20 , "mm" ) ;
255+ add ( "lineHeight" , 50 , "%" ) ;
256+ } ) ;
257+
206258test ( "css(String, Object)" , function ( ) {
207259 expect ( 19 ) ;
208260 var j , div , display , ret , success ;
0 commit comments