CSS3动画是网页设计当中非常重要的一部分,可以使页面变得更加生动和有趣。下面我们来分享一下关于CSS3动车行驶动画的代码。.train { : relative; width: 600px; hei...
CSS3动画是网页设计当中非常重要的一部分,可以使页面变得更加生动和有趣。下面我们来分享一下关于CSS3动车行驶动画的代码。
.train {
position: relative;
width: 600px;
height: 300px;
margin: 0 auto;
padding: 20px;
}
.train .body {
position: absolute;
top: 80px;
left: 0;
width: 300px;
height: 150px;
transform: rotate(-15deg);
background-color: #ccc;
border-radius: 10px;
z-index: 2;
}
.train .chimney {
position: absolute;
top: 50px;
left: 50px;
width: 50px;
height: 50px;
background-color: #999;
border-radius: 50% 50% 0 0;
transform: rotate(-45deg);
z-index: 3;
}
.train .wheel {
position: absolute;
top: 160px;
left: 20px;
width: 30px;
height: 30px;
background-color: #999;
border-radius: 50%;
animation: wheel-rotate 2s linear infinite;
z-index: 4;
}
@keyframes wheel-rotate {
0% {
transform: rotate(0);
}
100% {
transform: rotate(360deg);
}
}
.train .smoke {
position: absolute;
top: 0;
right: 0;
width: 50px;
height: 50px;
margin-top: -25px;
background-color: #fff;
border-radius: 50%;
opacity: 0;
transition: opacity 1s linear;
z-index: 5;
}
.train:hover .smoke {
opacity: 1;
}
.train:hover .wheel {
animation: wheel-rotate 2s linear reverse infinite;
} 以上代码实现了一个简单的火车行驶动画,包括火车的车身、烟囱和轮子。其中,轮子的动画使用了CSS3的animation属性,使其能够不停地旋转。而当鼠标放在火车上时,烟囱会冒出白色的圆形烟雾,使动画效果更加逼真。
总的来说,CSS3动画的实现需要对CSS的属性、选择器等进行深入的了解,才能够写出复杂、生动的动画效果。同时,前端开发者需要持续学习新的技术和工具,才能够跟上行业的变化和发展。