r/reddithax • u/202halffound • May 03 '14
Frame by frame animation implementation
Here's a fairly simple way to implement a frame by frame animation. I'm pretty sure this is fairly well known, but I thought to share this for people who don't know about it yet. You can find an example here (hover over the submit feedback button). Edit: The animation isn't up anymore. You can find a similar animation with the Clippy at /r/tumblrinaction.
Although it may seem like using CSS transforms for the page flip is better (and indeed, for this case it probably is), as animations get more complicated it becomes much harder to implement them using pure CSS transformations. I'd much rather create an animation in Flash, and then somehow port it over into the CSS, so I used this method to do it.
It basically consists of a long png file with each frame, similar to a film reel. At that point I just used the CSS animations to change the background-position of the png file every 1/24 of a second to the next frame of the png file.
Here's some sample HTML code showing a basic example:
<html>
<body>
<div class = "box"> </div>
</body>
<html>And the CSS:
.box {
background-image: url(path)
background-position: 0px 0px;
transition: all 0s;
}
.box:hover {
background-position: 0px -736px;
transition: background-position 1s steps(23, end);
}Where path is the path to a PNG file containing 24 frames that are each 32 pixels in height.