.bicycle{ width: 80%; margin: 50px auto; position: relative; animation: move 5s linear infinite; } .bicycle .wheel{ width: 50px; height: 50px; border-radius: 50%; border: 1px solid #000; position: absolute; } .bicycle .front-wheel{ top: 50%; left: -25px; animation: rotate_front 1s linear infinite; } .bicycle .back-wheel{ top: 50%; right: -25px; animation: rotate_back 1s linear infinite; } .bicycle .frame{ width: 60%; height: 30px; border-top: 5px solid #000; border-bottom: 5px solid #000; transform: skew(-15deg); position: relative; left: 20%; top: 25%; } .bicycle .saddle{ width: 5px; height: 20px; background-color: #000; position: absolute; top: 20%; left: 50%; margin-left: -2.5px; } .bicycle .handle-bar{ width: 20px; height: 5px; background-color: #000; position: absolute; top: 25%; left: 70%; transform-origin: bottom right; transform: rotate(-60deg); } @keyframes rotate_front { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } @keyframes rotate_back { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } } @keyframes move { from { left: -100%; } to { left: 100%; } }
以上代码中,使用了动画函数,通过调整左右移动和前后轮子的旋转来模拟骑行效果。同时还设置了自行车的框架、座椅、把手等细节,使得效果更加真实。在实际应用中,可以将这样的效果运用到自行车选购网站或相关活动网页之中,营造出更加活泼生动、富有互动性的用户体验。