I have designed front fascia of a car in CSS, and I would like to animate it from bottom to top, with charge filling in. How can I achieve that?
I am able to fill the bottom section of the car with it, but I want to do it for the whole car.
Any sort of suggestion/help will be highly appreciated. Please find the code for the same below,
.car-top {
position: relative;
border-bottom: 150px solid #555;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top-left-radius: 100px;
border-top-right-radius: 100px;
height: 0;
width: 350px;
}
.car-bottom {
position: relative;
width: 450px;
height: 80px;
background: #555;
}
.car-bottom:before {
content: "";
position: absolute;
background: #04ACFF;
width: 100%;
bottom: 0;
animation: wipe 2s cubic-bezier(.2,.6,.8,.4) forwards;
}
.tires:before, .tires:after {
content: "";
position: absolute;
width: 60px;
height: 50px;
top: 80px;
background: #555;
border-bottom-left-radius: 20px;
border-bottom-right-radius: 20px;
}
.tires:before {
left: 0;
}
.tires:after {
right: 0;
}
@keyframes wipe {
0% {
height: 0;
}
100% {
height: 100%;
}
}
<div class="parent">
<div class="car-top"></div>
<div class="car-bottom">
<div class="tires"></div>
</div>
</div>
3
Answers
have you tried using the same wipe animation to car top with an animation delay?
SVG clip path works best for this. (I just borrowed the SVG from Font Awesome; you can change it as you like.)
My own approach would be to avoid the artistry of HTML and CSS, and instead use an SVG along with the CSS
image-mask
property, as follows:JS Fiddle demo.
References:
@keyframes
.animation
.animation-duration
.animation-fill-mode
.animation-name
.animation-timing-function
.aspect-ratio
.background
.background-image
.background-position
.background-repeat
.background-size
.block-size
.display
.mask-image
.mask-position
.mask-size
.padding
.place-content
.