Skip to main content

Bug Tracker

Side navigation

#7616 closed enhancement (fixed)

Opened November 24, 2010 01:30PM UTC

Closed February 11, 2011 06:43AM UTC

Document and clean arguments of per-step callback in animate()

Reported by: checat Owned by:
Priority: low Milestone: 1.next
Component: effects Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

Currently animate() can animate only simple numeric CSS properties.

Animate options has a 'step' callback. It could be used to create any custom animation, but its parameters and usage are not properly documented (http://api.jquery.com/animate/). Currently it is called once for every animated CSS property and it is not called when no CSS properties given. Its first parameter is a numeric value of animated property.

Anyway, one can make use of it, using second argment, but it looks more like a hack. Following snippet animates text color from black to red:

jQuery('div').animate({opacity: 1}, {
    duration: 'slow',
    step: function (now, fx) {
        jQuery(this).css('color', 'rgb(' + Math.round(fx.pos*255) + ',0,0)');
}});

I think, exposed callback should have first parameter showing current animation 'completeness' (fx.pos, not fx.now), and it should be called only once per animation step no matter how many properties are animated, even 0 properties.

Attachments (0)
Change History (5)

Changed November 24, 2010 08:24PM UTC by jitter comment:1

component: unfiledeffects
keywords: → needsdocs
milestone: 1.51.4.5
priority: undecidedlow
status: newopen

I agree that this needs to be better documented.

The proposed enhancements to the step function don't look necessary to me as the second parameter fx contains just about everything you could need. e.g. completeness --> fx.state.

Changed November 29, 2010 09:23AM UTC by checat comment:2

Replying to [comment:1 jitter]:

The proposed enhancements to the step function don't look necessary to me

How about "it should be called only once per animation step no matter how many properties are animated"? Currently animate() makes quick exit when there are no properties (first arg is empty), and step function is not called at all in that case.

Changed December 01, 2010 02:04PM UTC by jitter comment:3

#7675 is a duplicate of this ticket.

Changed December 01, 2010 02:05PM UTC by jitter comment:4

Changed February 11, 2011 06:43AM UTC by addyosmani comment:5

keywords: needsdocs
resolution: → fixed
status: openclosed

The resolution for this ticket (based on the original discussion above) appears to have been that it required better documentation in order for it to be closed. As per jitter, I don't think the proposed enhancements are that necessary. With this in mind I've updated the animate()/step docs accordingly to reflect some clearer verbiage on how .step() actually works. http://api.jquery.com/animate/