Note that there are some explanatory texts on larger screens.

plurals
  1. POCSS3 Sprite Animation without tweening
    primarykey
    data
    text
    <p><strong>Read below for my final edit!</strong></p> <p>Is it possible to use CSS3 animations without having the animations tween between frames?</p> <p>For example, I have an image that I have two character animation sprites on. They are spaced evenly 50px. When I use the following animation I still get a tween (although a very fast tween so it can look like a flicker).</p> <pre><code>#ball .animated{ -webkit-animation-name: animate; -webkit-animation-duration: .5s; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: alternate; -webkit-animation-timing-function: linear;} @-webkit-keyframes animate{ 0%{-webkit-transform: translate3d(0,0,0);} 49%{-webkit-transform: translate3d(0,0,0);} 50%{-webkit-transform: translate3d(-50px,0,0);} 100%{-webkit-transform: translate3d(-50px,0,0);} </code></pre> <p>So based on the above, the sprite-frame should be held on the first part of the image (x = 0px) for the first 0-49% of the duration and then jump to second part of the image (x = -50px) for 50-100%. However, the 1% difference is still enough to visually see a tween from 0 to -50px.</p> <p>Thoughts?</p> <p>Edit:</p> <pre><code>-webkit-animation-timing-function: cubic-bezier(1,0,1,0); </code></pre> <p>The above seemed to straighten it out a bit but after a while it goes back to flickering.</p> <p>Edit: I hadn't realized that you could use decimals with the percentages. Closing the gap from 1% to 0.1% creates a much faster tween which is just about not visible (with a <code>-webkit-animation-duration:</code> &lt; 1s;)</p> <pre><code>0%{-webkit-transform: translate3d(0,0,0);} 49.9%{-webkit-transform: translate3d(0,0,0);} 50%{-webkit-transform: translate3d(-50px,0,0);} 100%{-webkit-transform: translate3d(-50px,0,0);} </code></pre> <p><strong>Final edit!:</strong> Ok, so from what I've found web-kit animations percentages will accept a decimal to the millionth place (i.e. 0.0001). Which on a relatively quick animation timer will result in an instantaneous translation. A little bit of a hack I suppose but it does the trick.</p> <p>Example:</p> <pre><code>@-webkit-keyframes sprite { 0% { -webkit-transform: translate3d(0,0,0); } 50% { -webkit-transform: translate3d(0,0,0); } 50.0001%{ -webkit-transform: translate3d(-50px,0,0); } 100%{ -webkit-transform: translate3d(-50px,0,0); } } </code></pre> <p>The above example is of an image of 100px (each sprite on the image is 50px wide) within a container div with the <code>width: 50px</code> and <code>overflow:hidden</code> to only show one sprite off the image at a time.</p> <p>Note: I am using translate3d because it is hardware accelerated in mobile browsers where translateX,translateY,translateZ are not yet hardware accelerated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload