2015-04-07 1 views
0

La boîte rouge est apparue au milieu de son containter lorsque la page charge mobile puis de gauche à droite et réapparaître comme cette image:animation CSS3 déplace vers la gauche pour continuer à droite, puis passer de l'extérieur à gauche

enter image description here

Voici ce que je l'ai fait jusqu'à présent, mais il ne convient pas à l'idée ci-dessus:

.box{ 
    -webkit-animation: left-to-right 10s infinite; /* Chrome, Safari, Opera */ 
    animation: left-to-right 10s infinite; 
} 

/* Chrome, Safari, Opera */ 
@-webkit-keyframes left-to-right { 
    100%{ 
     left:-1000px 
    } 
} 

@keyframes left-to-right { 
    100%{ 
     left:-1000px 
    } 
} 

page largeur est 1280px et la largeur de la boîte est 1000px.

+0

Lequel voulez-vous continuer à déplacer de l'extérieur vers la gauche? Le carré ou le rectangle? – EddNewGate

+0

un carré est une partie du rectangle qui est en dehors du contenu. Il n'y a qu'un seul objet en mouvement ici: le rectangle rouge – Lee

+0

Avez-vous essayé votre code aussi pour voir comment cela fonctionne? Dans votre animation affichée en exemple, vous avez deux objets en mouvement: un rectangle de gauche à droite et un carré de droite à gauche. Avec votre code publié, votre animation ne bougera même pas comme dans votre exemple. – EddNewGate

Répondre

1

Vous pouvez utiliser ceci:

http://codepen.io/anon/pen/dPEJzm

<div id="animated-example" class="animated shake"></div> 



.animated { 
    -webkit-animation-duration: 5s; 
    animation-duration: 5s; 
    -webkit-animation-fill-mode: both; 
    animation-fill-mode: both; 
    -webkit-animation-timing-function: linear; 
    animation-timing-function: linear; 
    animation-iteration-count:infinite; 
    -webkit-animation-iteration-count:infinite; 
} 

@-webkit-keyframes shake { 
    0%, 100% {-webkit-transform: translateX(0);} 
    10%, 30%, 50%, 70%, 90% {-webkit-transform: translateX(-50px);} 
    20%, 40%, 60%, 80% {-webkit-transform: translateX(50px);} 
} 
@keyframes shake { 
    0%, 100% {transform: translateX(0);} 
    10%, 30%, 50%, 70%, 90% {transform: translateX(-50px);} 
    20%, 40%, 60%, 80% {transform: translateX(50px);} 
} 
.shake { 
    -webkit-animation-name: shake; 
    animation-name: shake; 
} 
.shake { 
    background:red; 
    height:100px; 
    width:100px; 

} 
0

http://jsfiddle.net/bvjzmke5/3/

Je fais complète en 2s et utilisé -50% pour se déplacer, changement qui vous le voulez.

.box{ 
    -webkit-animation: right-to-left 2s linear infinite; /* Chrome, Safari, Opera */ 
    animation: right-to-left 2s linear infinite; 
} 

/* Chrome, Safari, Opera */ 
@-webkit-keyframes right-to-left { 

    100%{ 
     left:-50% 
     }  
} 

@keyframes left-to-right { 

    100%{ 
     left:-50% 
     }  

} 

.square{ 
    -webkit-animation: left-to-right 2s linear infinite; /* Chrome, Safari, Opera */ 
    animation: left-to-right 2s linear infinite; 
} 

/* Chrome, Safari, Opera */ 
@-webkit-keyframes left-to-right { 

    100%{ 
     right:-50% 
     }  
} 

@keyframes left-to-right { 
    100%{ 
     right:-50% 
     } 
} 

<div id="container" style="height:100px; width:60%; margin:0 auto"> 
<div class="box" style="height:100px; width:50%;background:red;position:relative;display:inline-block"></div> 
<div class="square" style="height:100px; width:100px; background:red;position:relative;display:inline-block"></div> 
</div>