This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 16521 - Rounding of integer values is inconsistent with SVG and SMIL
Summary: Rounding of integer values is inconsistent with SVG and SMIL
Status: RESOLVED FIXED
Alias: None
Product: CSS
Classification: Unclassified
Component: Transitions (show other bugs)
Version: unspecified
Hardware: All All
: P2 normal
Target Milestone: ---
Assignee: L. David Baron (Mozilla)
QA Contact: public-css-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-26 08:22 UTC by Brian Birtles
Modified: 2013-02-13 02:01 UTC (History)
5 users (show)

See Also:


Attachments

Description Brian Birtles 2012-03-26 08:22:00 UTC
As per the following thread on www-style, the behaviour defined for interpolating integer properties in CSS transitions (and hence CSS Animations) uses floor whilst SVG and SMIL use round.

  http://lists.w3.org/Archives/Public/www-style/2012Feb/0141.html

Unless a (good) argument is put forward to prefer the floor behaviour, CSS Transitions should align with SMIL and SVG on this issue.
Comment 1 Will Rice 2012-05-19 00:04:42 UTC
I wish to second the notion that using floor() to round to integer values creates a more intuitive animation behaviour from the point of view of a web developer.

I have also identified that at present, Webkit is contravening the W3C (draft) spec by using round() for CSS Animation of integer properties - presumably they are of the opinion that both SVG/SMIL and Animation/Transition should use round() to animate integer properties - I personally disagree (and instead agree with Brian).

http://code.google.com/p/chromium/issues/detail?id=128534
Comment 2 Will Rice 2012-05-19 00:25:26 UTC
EDIT: I misread Brian's original comment.

So in fact I disagree with Brian and agree those who originally wrote the W3C CSS Animation spec. It is my opinion that using floor() to round integer properties creates a more intuitive animation from the perspective of a web developer.

I propose that the SVG/SMIL spec should be adjusted to specify floor() rounding for integer animation.
Comment 3 Will Rice 2012-05-21 05:44:31 UTC
I have identified one situation in which floor() rounding allows for a much more elegant CSS animation solution to a simple problem.

http://dabblet.com/gist/2760288

I wish to propose that if/when the specification is changed to specify round() for the rounding of integer property animation/transition that it should simultaneously be changed to allow non-integer transition/keyframe values for integer properties and that these should be rounded only after interpolation has taken place.

In this way, a web designer would be able to create a floor() like behaviour simply by subtracting 0.5 from their keyframe/input values. At present the latest Webkit Nightly simply ignores non-integer input values for integer property animation.
Comment 4 Brian Birtles 2012-05-21 06:02:51 UTC
(In reply to comment #3)
> I have identified one situation in which floor() rounding allows for a much
> more elegant CSS animation solution to a simple problem.
> 
> http://dabblet.com/gist/2760288

You can achieve the desired effect even more elegantly using round by simply omitting the middle keyframe value for z-index:

@keyframes orbit {
    0% { margin-left: -150px; z-index: 10; }
    50% { margin-left: 100px; }
    100% { margin-left: -150px; z-index: 9; }
}

I'm sure it is possible to find some cases where floor more elegant. Likewise, there will also be some where round is more elegant.

The main issue is that if we make CSS use floor it will be very hard to make animations interchangeable between CSS and SVG (which is a Rec).

If you discover some really compelling reason for using floor then I'd encourage posting it to public-fx.
Comment 5 Will Rice 2012-05-21 06:07:22 UTC
I understand the obvious advantage of having animation&transition in line with SVG/SMIL. I was not proposing that floor() should be kept.

I was instead proposing that non-integer inputs should also be allowed.
Comment 6 Brian Birtles 2012-05-21 06:10:24 UTC
(In reply to comment #5)
> I understand the obvious advantage of having animation&transition in line with
> SVG/SMIL. I was not proposing that floor() should be kept.

Ok, sorry I misunderstood.

> I was instead proposing that non-integer inputs should also be allowed.

I think you achieve the desired effect by simply omitting property values from keyframes. This is something that's not clearly specified at the present time. There is a note in CSS Animations saying, "describe what happens if a property is not present in all keyframes" but I think when it is spelled out, it will give the effect desired in this case.
Comment 7 L. David Baron (Mozilla) 2013-02-13 02:01:16 UTC
Fixed in https://dvcs.w3.org/hg/csswg/rev/54cd45623730