html - CSS vehicle animation -
html - CSS vehicle animation -
i'm trying animate tractor moving across screen. i've got working on screen, want work across different platforms (only included -webkit-). when re-size, tractor fluid, wheels aren't. how can create them adjust together?
<body> <div class="container"> <div class="tractor"> <img src="img/tractor-700px.png" alt="tractor"> </div> <div class="wheels"> <div class="b_wheel"> <img src="img/b_wheel.png"> </div> <div class="f_wheel"> <img src="img/f_wheel.png"> </div> </div> </div>
here's main css:
.tractor { width: 380px; position: absolute; top: 40%; left: -5%; } .tractor img { width: 100%; } .tractor::after { content: ""; display: block; width: 120px; height: 120px; background: url('img/steam.png') no-repeat; background-size: 120px; position: absolute; top: -37%; left: 56%; opacity: 0; } .f_wheel {; width: 125px; position: absolute; top: 66.5%; left: 13%; } .f_wheel img { width: 100%; } .b_wheel { width: 190px; position: absolute; top: 58.8%; left: -7%; } .b_wheel img { width: 100%; }
and css animation:
.tractor { -webkit-animation: tractor-bounce 3s ease-in-out infinite, tractor-go 10s ease-in-out forwards; } .tractor::after { -webkit-animation: steam 4s 2s infinite; } .f_wheel, .b_wheel { -webkit-animation: wheel-spin 10s ease-in-out forwards; } .f_wheel { -webkit-animation: front-wheel-go 10s ease-in-out forwards, wheel-spin 10s ease-in-out forwards; } .b_wheel { -webkit-animation: back-wheel-go 10s ease-in-out forwards, wheel-spin 10s ease-in-out forwards; } /* keyframes - webkit ------------------------------------------ */ @-webkit-keyframes tractor-bounce { 50% { -webkit-transform: rotate(-5deg) translatey(-3px); } } @-webkit-keyframes tractor-go { 100% { left: 70%; } } @-webkit-keyframes steam { 40% { opacity: .8; } 60% { opacity: 1; } 100% { -webkit-transform: translate(-15%, -35%) rotatez(20deg); } } @-webkit-keyframes wheel-spin { 0% { -webkit-transform: translatex(0px) rotate(50deg); } 100% { -webkit-transform: translatex(0px) rotate(480deg); } } @-webkit-keyframes front-wheel-go { 100% { left: 88%; } } @-webkit-keyframes back-wheel-go { 100% { left: 68.5%; } }
jsfiddle show in action: http://jsfiddle.net/0j5l92vh/1/
[ps - first post here many in advance! allow me know if need include else.]
i found solution problem.
i utilized .container div have provided maintain positioned relative tractor image. can see changes in css code made create work in non webkit browsers. not work on versions of net explorer before number 9.
the changes have made css.
jsfiddle: http://jsfiddle.net/larryjoelane/h324j6u6/113/
css:
.container{ width: 380px; position: relative; /*bind animation , set properties*/ -webkit-animation: tractor 10s linear 0s; /* chrome, safari, opera */ animation: tractor 10s linear 0s; } /*bind wheel-spin animation*/ .f_wheel, .b_wheel { -webkit-animation: wheel-spin 10s ease-in-out forwards; animation: wheel-spin 10s ease-in-out forwards; } /*bind tractor bounce-animation*/ .tractor { -webkit-animation: tractor-bounce 3s ease-in-out infinite, tractor-go 10s ease-in-out forwards; animation: tractor-bounce 3s ease-in-out infinite, tractor-go 10s ease-in-out forwards; } .tractor img{ width:100%; } .b_wheel { width: 190px; position: relative; top: -120px; left: -7%; } .b_wheel img { width: 100%; } .f_wheel{ width: 125px; position:relative; top: -258px; left: 65%; } .f_wheel img { width: 100%; } /* chrome, safari, opera */ @-webkit-keyframes tractor { 0% { left:0px; top:0px;} 25% {left:200px; top:0px;} 50% {left:400px; top:0px;} 75% {left:600px; top:0px;} 100% {left:800px; top:0px;} } /* standard syntax */ @keyframes tractor { 0% { left:0px; top:0px;} 25% {left:200px; top:0px;} 50% {left:400px; top:0px;} 75% {left:600px; top:0px;} 100% {left:800px; top:0px;} } /*standard browser animation*/ @keyframes wheel-spin{ 0% { transform: translatex(0px) rotate(50deg); } 100% { transform: translatex(0px) rotate(480deg); } } /*webkit browser animation*/ @-webkit-keyframes wheel-spin{ 0% { -webkit-transform: translatex(0px) rotate(50deg); } 100% { -webkit-transform: translatex(0px) rotate(480deg); } } /*webkit tractor-bounce animation*/ @-webkit-keyframes tractor-bounce { 50% { -webkit-transform: rotate(-5deg) translatey(-3px); } } /*standard tractor-bounce web browser animation*/ @keyframes tractor-bounce { 50% { transform: rotate(-5deg) translatey(-3px); } }
html css animation
Comments
Post a Comment