Skip to main content

Bug Tracker

Side navigation

#1438 closed bug (fixed)

Opened July 30, 2007 10:31AM UTC

Closed December 04, 2007 06:24PM UTC

Last modified March 15, 2012 04:23PM UTC

Note to IE opacity filter

Reported by: hobbit Owned by:
Priority: major Milestone: 1.2.2
Component: effects Version: 1.1.3
Keywords: IE, filter Cc:
Blocked by: Blocking:
Description

The original code in the .attr method:

return elem.filter ?

(parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString():"";

If we defined a filter to the animated element, but don't modifie the opacity under jQuery amination, then the match will return null. This problem like http://dev.jquery.com/ticket/1101#comment:5, but we can't use this expression.

(parseFloat( (elem.filter.match(/opacity=([^)]*)/) || [])[1] )/100).toString();

This returns a "NaN" string. We should use this:

return elem.filter && /opacity=/.test(elem.filter)?
(elem.filter.match(/opacity=(\\d*)/)[1] / 100).toString() : "";

Now the division always returns a number, then we don't call the parseFloat function. Here you are the corrected code:

if ( jQuery.browser.msie && name == "opacity" ) {
  if ( value != undefined ) {
    // IE has trouble with opacity if it does not have layout
    // Force it by setting the zoom level
    elem.zoom = 1;

    // Set the alpha filter to set the opacity
    elem.filter = (elem.filter || "").replace(/alpha\\([^)]*\\)/, "") +
      (isNaN(parseFloat(value)) ? "" : "alpha(opacity=" + value * 100 + ")");
  }

  return elem.filter && /opacity=/.test(elem.filter)?
    (elem.filter.match(/opacity=(\\d*)/)[1] / 100).toString() : "";
}

And there are two .match callings in the curCSS method, but the .test is faster like .match to checking.

if (prop.match(/float/i))
if (/float/i.test(prop))
Attachments (0)
Change History (1)

Changed December 04, 2007 06:24PM UTC by davidserduke comment:1

milestone: 1.1.41.2.2
resolution: → fixed
status: newclosed

Fixed in [4013]. There are various other changes the author proposed but didn't spell out why or what they fixed so those changes were not made. For example the description changes the current RegExp from

/opacity=([^)]*)/

to

/opacity=(\\d*)/

without saying why. It seems to me that would fail on a floating point number but I didn't test it. If the other changes made outside the JS null error are there for good reasons please reopen this ticket (or open a new one) with those details.