html - Background transition with sprite image in css3? -


any 1 please give me correct approach using css3?

1) have on bg image contains multiple states of each sprite.

i using keyframe animation update each of position of backgroud, not come well

how it? if not wrong 1 show correct way please?

my code :

<div class="bg"></div>  div.bg {     background : url(https://dl.dropboxusercontent.com/u/10268257/all.png) 0 center;     height:443px;     width:795px; }  @-webkit-keyframes animatebg {     0%{ background-position :0px center}     5.882352941176471%{ background-position :795px center}     11.764705882352942%{ background-position :1590px center}     17.647058823529413%{ background-position :2385px center}     23.529411764705884%{ background-position :3180px center}     29.411764705882355%{ background-position :3975px center}     35.294117647058826%{ background-position :4770px center}     41.1764705882353%{ background-position :5565px center}     47.05882352941177%{ background-position :6360px center}     52.94117647058824%{ background-position :7155px center}     58.82352941176471%{ background-position :7950px center}     64.70588235294119%{ background-position :8745px center}     70.58823529411765%{ background-position :9540px center}     76.47058823529412%{ background-position :10335px center}     82.3529411764706%{ background-position :11130px center}     88.23529411764707%{ background-position :11925px center}     23 94.11764705882354%{ background-position :12720px center} }  div.bg:hover {       animation-name: animatebg;         animation-duration: 4s; } 

jsfiddle

it's because need define number of steps , put animation total length, divide itself.

(change '1s' speed or slow down animation)

div.bg {     background : url(https://dl.dropboxusercontent.com/u/10268257/all.png);     height:443px;     width:795px;     -webkit-animation: animatebg 1s steps(16) infinite;        -moz-animation: animatebg 1s steps(16) infinite;         -ms-animation: animatebg 1s steps(16) infinite;          -o-animation: animatebg 1s steps(16) infinite;             animation: animatebg 1s steps(16) infinite;     margin:0; }  @-webkit-keyframes animatebg {    { background-position:    0px; }      { background-position: -12720px; } }  @-moz-keyframes animatebg {        { background-position:    0px; }          { background-position: -12720px; } }  @-ms-keyframes animatebg {        { background-position:    0px; }          { background-position: -12720px; } }  @-o-keyframes animatebg {        { background-position:    0px; }          { background-position: -12720px; } }  @keyframes animatebg {        { background-position:    0px; }          { background-position: -12720px; } } 

http://jsfiddle.net/oe27u6sq/5/

and on:hover http://jsfiddle.net/oe27u6sq/6/


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -