Bug Tracker

Opened 8 years ago

Closed 6 years ago

Last modified 5 years ago

#2954 closed bug (fixed)

Use isNaN for IE opacity

Reported by: lrbabe Owned by: flesler
Priority: major Milestone: 1.3
Component: css Version: 1.2.5
Keywords: Cc:
Blocked by: Blocking:


function attr of core.js (the second one) use a strange test to detect NaN :

parseInt( value ) + "" == "NaN" ?

If appropriate, replace it with :


See proposed patch.

Change History (8)

comment:1 Changed 8 years ago by flesler

  • Owner set to flesler
  • Status changed from new to assigned

I wanted to do the same change some weeks ago. But for some reason the results were different.

comment:2 Changed 8 years ago by lrbabe

By the way, if we are just testing if the value is a number, shouldn't we use value.constructor == Number ?

comment:3 Changed 8 years ago by lrbabe

oops oops oops, never mind my last comment.

comment:4 Changed 8 years ago by lrbabe

... actually you can mind it.

comment:5 Changed 8 years ago by flesler

No, because it's a string. So value.constructor == String.

comment:6 Changed 8 years ago by flesler

Right. The change could probably fit. I don't see much gain but might make it in. Will check this asap, it requires a lot of testing.

comment:7 Changed 6 years ago by dmethvin

  • Component changed from core to css
  • Summary changed from [patch] Use isNaN if appropriate to Use isNaN for IE opacity

Here's the current line in 1.4.2:

var opacity = parseInt( value, 10 ) + "" === "NaN" ? "" : "alpha(opacity=" + value * 100 + ")";

parseInt() only looks for valid leading digits that can be followed by non-digits, but isNaN() requires the entire string to be a valid number. Opacity should be a number from 0.0 to 1.0 (not an integer). Also the Microsoft docs say the opacity should be an integer from 0 to 100.


So it seems like the correct line would be this:

var opacity = isNaN(value) ? "" : "alpha(opacity=" + Math.round(value * 100) + ")";

comment:8 Changed 6 years ago by dmethvin

  • Resolution set to fixed
  • Status changed from assigned to closed

Implemented in the rewrite of csshooks in 1.4.3.

Note: See TracTickets for help on using tickets.