当前位置:Gxlcms > css > css3实现动画自行车效果

css3实现动画自行车效果

时间:2021-07-01 10:21:17 帮助过:33人阅读

这次给大家带来css3实现动画自行车效果,css3实现动画自行车效果的注意事项有哪些,下面就是实战案例,一起来看一下。

首先来看看实现的效果图(静态):

实例源码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>自行车</title>
  6. <style type="text/css">
  7. * {
  8. margin: 0;
  9. padding: 0
  10. }
  11. ol,
  12. ul {
  13. list-style: none/*去掉圆点或数字*/
  14. }
  15. .cycle-outer {
  16. width: 534px;
  17. height: 260px;
  18. position: absolute;
  19. /*绝对定位*/
  20. top: 50%;
  21. /*距离顶部*/
  22. margin: -160px 0 0 -267px;
  23. /*距离外边距*/
  24. left: 50%;
  25. }
  26. .cycle-wrapper {
  27. width: 534px;
  28. height: 260px;
  29. margin: 0 auto;
  30. position: relative;
  31. /*相对定位*/
  32. }
  33. .cycle-wheel-front {
  34. /*前轮*/
  35. margin: 100px 0 0 330px;
  36. }
  37. .cycle-wheel-back {
  38. /*后轮*/
  39. margin: 100px 0 0 0px;
  40. }
  41. .cycle-wheel-outer {
  42. background: transparent;
  43. border: 5px solid #aaa;
  44. border-radius: 50%;
  45. /*画外轮圆圈*/
  46. width: 190px;
  47. height: 190px;
  48. position: absolute;
  49. margin-top: 5px;
  50. animation: wheel-rotate 2s linear infinite;
  51. /*定义动画*/
  52. }
  53. /*轮胎开始旋转*/
  54. @keyframes wheel-rotate {
  55. from {
  56. transform: rotate(0deg);
  57. }
  58. to {
  59. transform: rotate(360deg);
  60. }
  61. }
  62. .cycle-wheel-outer:after {
  63. /*插入内轮胎圆圈*/
  64. background: transparent;
  65. border: 4px solid #EF9058;
  66. border-radius: 50%;
  67. width: 176px;
  68. height: 176px;
  69. position: absolute;
  70. margin: 3px;
  71. content: "";
  72. }
  73. .spoke {
  74. /*开始画车轮线条*/
  75. position: absolute;
  76. width: 1px;
  77. height: 200px;
  78. background: #ccc;
  79. margin: -5px 0 0 95px;
  80. z-index: 0;
  81. }
  82. .spoke:after {
  83. /*在后面插入两条*/
  84. content: "";
  85. position: absolute;
  86. width: 1px;
  87. height: 200px;
  88. background: #ccc;
  89. transform: rotate(120deg);
  90. }
  91. .spoke:before {
  92. /*在前面插入两条*/
  93. content: "";
  94. position: absolute;
  95. width: 1px;
  96. height: 200px;
  97. background: #ccc;
  98. transform: rotate(240deg);
  99. }
  100. /*轮胎线条完成*/
  101. .spoke-container li:nth-child(2) {
  102. /*中心点旋转*/
  103. transform: rotate(30deg);
  104. }
  105. .inner-disc {
  106. /*画中心轴圆点*/
  107. background: #666;
  108. width: 20px;
  109. height: 20px;
  110. border-radius: 50%;
  111. position: absolute;
  112. left: 50%;
  113. margin: -10px 0 0 -10px;
  114. top: 50%;
  115. }
  116. /*.cycle-wheel-back .inner-disc:after {
  117. content: "";
  118. background: #666;
  119. width: 20px;
  120. height: 20px;
  121. border-radius: 50%;
  122. position: absolute;
  123. left: 50%;
  124. margin: -10px 0 0 -10px;
  125. top: 50%;
  126. }*/
  127. .inner-disc-2 {
  128. /*画轮胎中心轴的圆圈*/
  129. background: transparent;
  130. width: 6px;
  131. height: 6px;
  132. border: 2px solid #FFF;
  133. border-radius: 50%;
  134. position: absolute;
  135. left: 50%;
  136. margin: -5px 0 0 -5px;
  137. top: 50%;
  138. }
  139. .cycle-wheel-back .inner-disc-2:after {
  140. /*插入后轮轴心齿轮*/
  141. content: "";
  142. background: transparent;
  143. width: 18px;
  144. height: 18px;
  145. border-radius: 50%;
  146. position: absolute;
  147. left: 50%;
  148. margin: -13px 0 0 -13px;
  149. top: 50%;
  150. border: 4px dotted #666;
  151. }
  152. .cycle-body {
  153. margin-left: 125px;
  154. }
  155. .front-wheel-frame {/*前叉*/
  156. background: #5E999B;
  157. width: 8px;
  158. height: 180px;
  159. position: absolute;
  160. z-index: 2;
  161. transform: rotate(-25deg);
  162. margin: -72px 0 0 260px;
  163. }
  164. .top-frame {/*上管*/
  165. background: #5E999B;
  166. width: 180px;
  167. height: 8px;
  168. position: absolute;
  169. z-index: 2;
  170. margin: -20px 0 0 62px;
  171. transform: rotate(-8deg);
  172. }
  173. .front-frame {/*下管*/
  174. background: #5E999B;
  175. width: 8px;
  176. height: 160px;
  177. position: absolute;
  178. z-index: 2;
  179. transform: rotate(41deg);
  180. margin: -36px 0 0 189px;
  181. }
  182. .center-frame { /*坐杆*/
  183. background: #5E999B;
  184. width: 8px;
  185. height: 205px;
  186. position: absolute;
  187. z-index: 2;
  188. transform: rotate(-33deg);
  189. margin: -84px 0 0 75px;
  190. }
  191. .back-frame {/*后管*/
  192. background: #5E999B;
  193. width: 8px;
  194. height: 136px;
  195. position: absolute;
  196. z-index: 2;
  197. transform: rotate(39deg);
  198. margin: -23px 0 0 19px;
  199. }
  200. .bottom-frame {/*后叉or平管*/
  201. background: #5E999B;
  202. width: 159px;
  203. height: 8px;
  204. position: absolute;
  205. z-index: 2;
  206. margin: 100px 0 0 -16px;
  207. }
  208. .handlebar-front {/*车把*/
  209. width: 60px;
  210. height: 8px;
  211. background: #5E999B;
  212. z-index: 2;
  213. position: absolute;
  214. margin: -68px 0 0 222px;
  215. border-top-left-radius: 3px;
  216. border-bottom-left-radius: 3px;
  217. }
  218. .handlebar-curve {/*车把手*/
  219. width: 40px;
  220. height: 40px;
  221. border: 8px solid #666;
  222. border-top-right-radius: 100%;
  223. border-bottom-right-radius: 100%;
  224. border-bottom-left-radius: 100%;
  225. background: transparent;
  226. position: absolute;
  227. margin: -68px 0 0 258px;
  228. border-left: 8px solid transparent;
  229. border-top: 8px solid #666;
  230. border-bottom: 8px solid #666;
  231. }
  232. /*座垫*/
  233. .seat {
  234. width: 50px;
  235. height: 10px;
  236. background: #666;
  237. border-radius: 44%;
  238. position: absolute;
  239. margin: -73px 0 0 15px;
  240. }
  241. .seat:after {
  242. width: 0px;
  243. height: 0px;
  244. border-style: solid;
  245. border-width: 0 40px 16px 40px;
  246. border-color: transparent transparent #666 transparent;
  247. content: "";
  248. position: absolute;
  249. z-index: 3;
  250. transform: rotate(-12deg);
  251. position: absolute;
  252. border-radius: 100%;
  253. margin: 0 0 0 -26px;
  254. }
  255. .seat:before {
  256. width: 0px;
  257. height: 0px;
  258. border-style: solid;
  259. border-width: 0 40px 16px 40px;
  260. border-color: transparent transparent #666 transparent;
  261. content: "";
  262. position: absolute;
  263. z-index: 3;
  264. transform: rotate(179deg);
  265. position: absolute;
  266. border-radius: 100%;
  267. margin: 0 0 0 -26px;
  268. }
  269. .seat span {
  270. width: 32px;
  271. height: 19px;
  272. background: #666;
  273. border-radius: 100%;
  274. position: absolute;
  275. margin: 1px 0 0 -22px;
  276. transform: rotate(-11deg);
  277. }
  278. /*去掉中心轴的*/
  279. .chain-rotation {
  280. position: absolute;
  281. z-index: 16;
  282. }
  283. /*中心轴*/
  284. .chain-disc-inner {
  285. background: #666;
  286. width: 18px;
  287. height: 18px;
  288. border-radius: 50%;
  289. position: absolute;
  290. margin: 2px;
  291. z-index: 4;
  292. }
  293. .chain-disc-outer {
  294. background: #FFF;
  295. width: 22px;
  296. height: 22px;
  297. border: 5px solid #666;
  298. border-radius: 50%;
  299. position: absolute;
  300. margin: 87px 0 0 250px;
  301. z-index: 3;
  302. content: "";
  303. }
  304. /*牙盘*/
  305. .chain-rods {
  306. height: 70px;
  307. width: 6px;
  308. background: #666;
  309. position: absolute;
  310. margin: 67px 0 0 263px;
  311. z-index: 15;
  312. animation: wheel-rotate 2s linear infinite;
  313. }
  314. .chain-rods:before {
  315. content: "";
  316. height: 70px;
  317. width: 6px;
  318. background: #666;
  319. position: absolute;
  320. transform: rotate(120deg);
  321. }
  322. .chain-rods:after {
  323. content: "";
  324. height: 70px;
  325. width: 6px;
  326. background: #666;
  327. position: absolute;
  328. transform: rotate(240deg);
  329. -webkit-transform: rotate(240deg);
  330. -moz-transform: rotate(240deg);
  331. }
  332. .outer-axle {
  333. height: 70px;
  334. width: 70px;
  335. border-radius: 50%;
  336. background: transparent;
  337. border: 5px solid #666;
  338. position: absolute;
  339. margin: 62px 0 0 226px;
  340. z-index: 3;
  341. }
  342. .outer-axle:after {
  343. content: "";
  344. height: 74px;
  345. width: 74px;
  346. border-radius: 50%;
  347. background: transparent;
  348. border: 5px dotted #666;
  349. margin: -7px;
  350. position: absolute;
  351. z-index: 3;
  352. animation: wheel-rotate 2s linear infinite;
  353. }
  354. /*车链子*/
  355. .chain-up {
  356. background-color: transparent;
  357. background-size: 8px 2px;
  358. background-position: 0 0, 30px 30px;
  359. width: 155px;
  360. height: 4px;
  361. position: absolute;
  362. z-index: 9;
  363. background: #EEE;
  364. transform: rotate(-11deg);
  365. margin: 76px 0 0 98px;
  366. }
  367. .chain-up:before {
  368. content: "";
  369. background-color: transparent;
  370. background-image: linear-gradient(90deg, #666 25%, transparent 25%, transparent 75%, #666 75%, #666);
  371. background-size: 8px 2px;
  372. background-position: 0 0, 30px 30px;
  373. width: 155px;
  374. height: 4px;
  375. animation: chainUp 2s linear infinite;
  376. position: absolute;
  377. z-index: 10;
  378. }
  379. .chain-bottom {
  380. background-color: transparent;
  381. background-size: 8px 2px;
  382. background-position: 0 0, 30px 30px;
  383. width: 155px;
  384. height: 4px;
  385. position: absolute;
  386. z-index: 9;
  387. background: #EEE;
  388. -webkit-transform: rotate(9deg);
  389. -moz-transform: rotate(9deg);
  390. transform: rotate(9deg);
  391. margin: 127px 0 0 98px;
  392. }
  393. .chain-bottom:before {
  394. content: "";
  395. background-color: transparent;
  396. background-image: linear-gradient(90deg, #666 25%, transparent 25%, transparent 75%, #666 75%, #666);
  397. background-size: 8px 2px;
  398. background-position: 0 0, 30px 30px;
  399. width: 155px;
  400. height: 4px;
  401. animation: chainDown 2s linear infinite;
  402. position: absolute;
  403. z-index: 10;
  404. }
  405. /*脚踏*/
  406. .pedal-rod {
  407. height: 120px;
  408. width: 6px;
  409. background: #666;
  410. position: absolute;
  411. margin: -25px 0 0 0px;
  412. }
  413. .pedal-rod:before {
  414. width: 40px;
  415. height: 10px;
  416. background: #666;
  417. position: absolute;
  418. margin: 10px;
  419. content: "";
  420. margin: -7px -17px;
  421. animation: pedal1 2s linear infinite;
  422. }
  423. .pedal-rod:after {
  424. width: 40px;
  425. height: 10px;
  426. background: #666;
  427. position: absolute;
  428. margin: 10px;
  429. content: "";
  430. margin: 119px -17px;
  431. animation: pedal2 2s linear infinite;
  432. }
  433. /*水壶架*/
  434. .bottle-holder {
  435. width: 20px;
  436. height: 36px;
  437. background: #daeded;
  438. border: 3px solid #5E999B;
  439. position: absolute;
  440. margin: 54px 0 0 -25px;
  441. }
  442. .bottle-holder:after {
  443. width: 20px;
  444. height: 3px;
  445. content: "";
  446. background: #5E999B;
  447. position: absolute;
  448. margin: 24px 0 0 0px;
  449. }
  450. /*水壶*/
  451. .bottle-holder:before {
  452. background-color: #daeded;
  453. width: 18px;
  454. height: 10px;
  455. border-radius: 30% / 100%;
  456. border-bottom-left-radius: 0;
  457. border-bottom-right-radius: 0;
  458. content: "";
  459. position: absolute;
  460. margin-top: -13px;
  461. border: 1px solid #98baba;
  462. border-bottom: 0;
  463. }
  464. .bottle-holder span {
  465. position: absolute;
  466. width: 9px;
  467. height: 4px;
  468. background: #666;
  469. margin: -17px 0 0 5px;
  470. }
  471. /*车链子动画*/
  472. @keyframes chainUp {
  473. 0% {
  474. background-position: 0 25%;
  475. }
  476. 100% {
  477. background-position: 100% 0;
  478. }
  479. }
  480. @keyframes chainDown {
  481. 0% {
  482. background-position: 100% 0;
  483. }
  484. 100% {
  485. background-position: 0 25%;
  486. }
  487. }
  488. /*脚踏动画*/
  489. @keyframes pedal1 {
  490. 0% {
  491. transform: rotate(00deg);
  492. }
  493. 25% {
  494. transform: rotate(-140deg);
  495. }
  496. 50% {
  497. transform: rotate(-180deg);
  498. }
  499. 75% {
  500. transform: rotate(-240deg);
  501. }
  502. 100% {
  503. transform: rotate(-360deg);
  504. }
  505. }
  506. @keyframes pedal2 {
  507. 0% {
  508. transform: rotate(00deg);
  509. }
  510. 25% {
  511. transform: rotate(-60deg);
  512. }
  513. 50% {
  514. transform: rotate(-180deg);
  515. }
  516. 75% {
  517. transform: rotate(-340deg);
  518. }
  519. 100% {
  520. transform: rotate(-360deg);
  521. }
  522. }
  523. </style>
  524. </head>
  525. <body>
  526. <p class="cycle-outer">
  527. <p class="cycle-wrapper">
  528. <!--
  529. 描述:车架
  530. -->
  531. <p class="cycle-body">
  532. <p class="seat">
  533. <span></span>
  534. </p>
  535. <p class="front-wheel-frame"></p>
  536. <p class="top-frame"></p>
  537. <p class="front-frame">
  538. <p class="bottle-holder">
  539. <span></span>
  540. </p>
  541. </p>
  542. <p class="center-frame"></p>
  543. <p class="back-frame"></p>
  544. <p class="bottom-frame"></p>
  545. <p class="handlebar-front"></p>
  546. <p class="handlebar-curve"></p>
  547. </p>
  548. <!--
  549. 描述:后轮
  550. -->
  551. <p class="cycle-wheel cycle-wheel-back">
  552. <p class="cycle-wheel-outer">
  553. <p class="cycle-wheel-inner">
  554. <p class="cycle-wheel-inner-padding">
  555. <ul class="spoke-container">
  556. <li class="spoke"></li>
  557. <li class="spoke"></li>
  558. </ul>
  559. <p class="inner-disc"></p>
  560. <p class="inner-disc-2"></p>
  561. </p>
  562. </p>
  563. </p>
  564. </p>
  565. <!--
  566. 描述:前轮
  567. -->
  568. <p class="cycle-wheel cycle-wheel-front">
  569. <p class="cycle-wheel-outer">
  570. <p class="cycle-wheel-inner">
  571. <p class="cycle-wheel-inner-padding">
  572. <ul class="spoke-container">
  573. <li class="spoke"></li>
  574. <li class="spoke"></li>
  575. </ul>
  576. <p class="inner-disc"></p>
  577. <p class="inner-disc-2"></p>
  578. </p>
  579. </p>
  580. </p>
  581. </p>
  582. <!--
  583. 描述:中心轴 车链子 牙盘 水壶架 水壶 脚踏
  584. -->
  585. <p class="chain-up"></p>
  586. <p class="chain-bottom"></p>
  587. <p class="chain-rotation">
  588. <p class="outer-axle"></p>
  589. <p class="chain-disc-outer">
  590. <p class="chain-disc-inner"></p>
  591. </p>
  592. </p>
  593. <p class="chain-rods">
  594. <p class="pedal-rod"></p>
  595. </p>
  596. </p>
  597. </p>
  598. <p style="text-align:center;clear:both;">
  599. </body>
  600. </html>

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

css3多类选择器使用详解

css做出波纹动画

css的background-attachment进阶使用方法

以上就是css3实现动画自行车效果的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行