Bug Tracker

Modify

Ticket #1438 (closed bug: fixed)

Opened 6 years ago

Last modified 14 months ago

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:
Blocking: Blocked by:

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))

Change History

comment:1 Changed 5 years ago by davidserduke

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone changed from 1.1.4 to 1.2.2

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.