Ticket #7616 (closed enhancement: fixed)
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: | ||
| Blocking: | Blocked by: |
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.
Change History
comment:1 follow-up: ↓ 2 Changed 3 years ago by jitter
- Keywords needsdocs added
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to effects
- Milestone changed from 1.5 to 1.4.5
comment:2 in reply to: ↑ 1 Changed 3 years ago by checat
Replying to 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.
comment:5 Changed 2 years ago by addyosmani
- Keywords needsdocs removed
- Status changed from open to closed
- Resolution set to fixed
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/
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

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.