Bug Tracker

Opened 9 years ago

Closed 9 years ago

#15169 closed bug (migrated)

Error with .animate() on plain object

Reported by: dmethvin Owned by: gibson042
Priority: low Milestone: 1.12/2.2
Component: effects Version: 1.11.1
Keywords: Cc:
Blocked by: Blocking:




Not sure if $.animate intend to support generic object. The code below raise exception "Uncaught TypeError: Cannot use 'in' operator to search for 'opacity' in undefined"

var s = { opacity: 1 };
$(s).animate({opacity: 0}, 5000);

But it try to use $.css to set the opacity. So if I just change to other name

var s = { opacity2: 1 };
$(s).animate({opacity2: 0}, 5000);

and it works.

I guess it might be resolvable If jquery can detect if it's the html object or not. But not sure if $.animate intend to only support html object.

Change History (6)

comment:1 Changed 9 years ago by Timmy Willison

Component: unfiledeffects
Priority: undecidedlow
Status: newopen

If we support this, we should support it everywhere. In other words, we should have tests for it everywhere. I think we already do in some places, but the point is let's not just add tests for .animate().

comment:2 Changed 9 years ago by gibson042

From http://api.jquery.com/animate/:

The .animate() method allows us to create animation effects on any numeric CSS property. The only required parameter is a plain object of CSS properties. This object is similar to the one that can be sent to the .css() method, except that the range of properties is more restrictive.

So we're not explicitly supporting .animate of plain-object properties in our documentation, but this is actually a bug in the underlying jQuery.Animation (for which we do have unit tests).

The issue appears to be a problematic interaction with jQuery.cssNumber and unit conversion in the default tweener. My inclination is to ignore units unless tween.elem.nodeType === 1, because I don't think there's much of a case (to intentionally understate what's already a dusty corner of the API) for animating non-numeric properties on plain objects... thoughts?

comment:3 Changed 9 years ago by Timmy Willison

Since we have unit tests in this area already, I'd mark this as a regression that should be fixed.

comment:4 Changed 9 years ago by dmethvin

Milestone: None1.12/2.2

Agreed. Thanks for the analysis @gibson042!

comment:5 Changed 9 years ago by gibson042

Owner: set to gibson042
Status: openassigned

comment:6 Changed 9 years ago by m_gol

Resolution: migrated
Status: assignedclosed
Note: See TracTickets for help on using tickets.