温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何利用纯CSS3实现动态的自行车特效

发布时间:2021-06-18 15:10:27 阅读:135 作者:小新 栏目:web开发
前端开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章主要介绍如何利用纯CSS3实现动态的自行车特效,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

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

如何利用纯CSS3实现动态的自行车特效

实例源码:

<!DOCTYPE html>
<html>

 <head>
  <meta charset="UTF-8">
  <title>自行车</title>
  <style type="text/css">
   * {
    margin0;
    padding0
   }
   
   ol,
   ul {
    list-style: none/*去掉圆点或数字*/
   }
   
   .cycle-outer {
    width534px;
    height260px;
    position: absolute;
    /*绝对定位*/
    top50%;
    /*距离顶部*/
    margin: -160px 0 0 -267px;
    /*距离外边距*/
    left50%;
   }
   
   .cycle-wrapper {
    width534px;
    height260px;
    margin0 auto;
    position: relative;
    /*相对定位*/
   }
   
   .cycle-wheel-front {
    /*前轮*/
    margin100px 0 0 330px;
   }
   
   .cycle-wheel-back {
    /*后轮*/
    margin100px 0 0 0px;
   }
   
   .cycle-wheel-outer {
    background: transparent;
    border5px solid #aaa;
    border-radius50%;
    /*画外轮圆圈*/
    width190px;
    height190px;
    position: absolute;
    margin-top5px;
    animation: wheel-rotate 2s linear infinite;
    /*定义动画*/
   }
   /*轮胎开始旋转*/
   @keyframes wheel-rotate {
    from {
     transformrotate(0deg);
    }
    to {
     transformrotate(360deg);
    }
   }
   
   .cycle-wheel-outer:after {
    /*插入内轮胎圆圈*/
    background: transparent;
    border4px solid #EF9058;
    border-radius50%;
    width176px;
    height176px;
    position: absolute;
    margin3px;
    content"";
   }
   
   .spoke {
    /*开始画车轮线条*/
    position: absolute;
    width1px;
    height200px;
    background#ccc;
    margin: -5px 0 0 95px;
    z-index0;
   }
   
   .spoke:after {
    /*在后面插入两条*/
    content"";
    position: absolute;
    width1px;
    height200px;
    background#ccc;
    transformrotate(120deg);
   }
   
   .spoke:before {
    /*在前面插入两条*/
    content"";
    position: absolute;
    width1px;
    height200px;
    background#ccc;
    transformrotate(240deg);
   }
   /*轮胎线条完成*/
   
   .spoke-container li:nth-child(2) {
    /*中心点旋转*/
    transformrotate(30deg);
   }
   
   .inner-disc {
    /*画中心轴圆点*/
    background#666;
    width20px;
    height20px;
    border-radius50%;
    position: absolute;
    left50%;
    margin: -10px 0 0 -10px;
    top50%;
   }
   /*.cycle-wheel-back .inner-disc:after {
    content: "";
    background: #666;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    position: absolute;
    left: 50%;
    margin: -10px 0 0 -10px;
    top: 50%;
   }*/
   
   .inner-disc-2 {
    /*画轮胎中心轴的圆圈*/
    background: transparent;
    width6px;
    height6px;
    border2px solid #FFF;
    border-radius50%;
    position: absolute;
    left50%;
    margin: -5px 0 0 -5px;
    top50%;
   }
   
   .cycle-wheel-back .inner-disc-2:after {
    /*插入后轮轴心齿轮*/
    content"";
    background: transparent;
    width18px;
    height18px;
    border-radius50%;
    position: absolute;
    left50%;
    margin: -13px 0 0 -13px;
    top50%;
    border4px dotted #666;
   }
   .cycle-body {
    margin-left125px;
   }
   .front-wheel-frame {/*前叉*/
    background#5E999B;
    width8px;
    height180px;
    position: absolute;
    z-index2;
    transformrotate(-25deg);
    margin: -72px 0 0 260px;
   }
   .top-frame {/*上管*/
    background#5E999B;
    width180px;
    height8px;
    position: absolute;
    z-index2;
    margin: -20px 0 0 62px;
    transformrotate(-8deg);
   }
   .front-frame {/*下管*/
    background#5E999B;
    width8px;
    height160px;
    position: absolute;
    z-index2;
    transformrotate(41deg);
    margin: -36px 0 0 189px;
   }
   .center-frame { /*坐杆*/
    background#5E999B;
    width8px;
    height205px;
    position: absolute;
    z-index2;
    transformrotate(-33deg);
    margin: -84px 0 0 75px;
   }
   .back-frame {/*后管*/
    background#5E999B;
    width8px;
    height136px;
    position: absolute;
    z-index2;
    transformrotate(39deg);
    margin: -23px 0 0 19px;
   }
   .bottom-frame {/*后叉or平管*/
    background#5E999B;
    width159px;
    height8px;
    position: absolute;
    z-index2;
    margin100px 0 0 -16px;
   }
   .handlebar-front {/*车把*/
    width60px;
    height8px;
    background#5E999B;
    z-index2;
    position: absolute;
    margin: -68px 0 0 222px;
    border-top-left-radius3px;
    border-bottom-left-radius3px;
   }
   .handlebar-curve {/*车把手*/
    width40px;
    height40px;
    border8px solid #666;
    border-top-right-radius100%;
    border-bottom-right-radius100%;
    border-bottom-left-radius100%;
    background: transparent;
    position: absolute;
    margin: -68px 0 0 258px;
    border-left8px solid transparent;
    border-top8px solid #666;
    border-bottom8px solid #666;
   }
   /*座垫*/
   .seat { 
    width50px;
    height10px;
    background#666;
    border-radius44%;
    position: absolute;
    margin: -73px 0 0 15px;
   }
   
   .seat:after {
    width0px;
    height0px;
    border-style: solid;
    border-width0 40px 16px 40px;
    border-color: transparent transparent #666 transparent;
    content"";
    position: absolute;
    z-index3;
    transformrotate(-12deg);
    position: absolute;
    border-radius100%;
    margin0 0 0 -26px;
   }
   .seat:before {
    width0px;
    height0px;
    border-style: solid;
    border-width0 40px 16px 40px;
    border-color: transparent transparent #666 transparent;
    content"";
    position: absolute;
    z-index3;
    transformrotate(179deg);
    position: absolute;
    border-radius100%;
    margin0 0 0 -26px;
   }
   .seat span {
    width32px;
    height19px;
    background#666;
    border-radius100%;
    position: absolute;
    margin1px 0 0 -22px;
    transformrotate(-11deg);
   }
   /*去掉中心轴的*/
   .chain-rotation {
    position: absolute;
    z-index16;
   }
   /*中心轴*/
   .chain-disc-inner {
    background#666;
    width18px;
    height18px;
    border-radius50%;
    position: absolute;
    margin2px;
    z-index4;
   }
   .chain-disc-outer {
    background#FFF;
    width22px;
    height22px;
    border5px solid #666;
    border-radius50%;
    position: absolute;
    margin87px 0 0 250px;
    z-index3;
    content"";
   }
   /*牙盘*/
   .chain-rods {
    height70px;
    width6px;
    background#666;
    position: absolute;
    margin67px 0 0 263px;
    z-index15;
    animation: wheel-rotate 2s linear infinite;
   }
   .chain-rods:before {
    content"";
    height70px;
    width6px;
    background#666;
    position: absolute;
    transformrotate(120deg);
   }
   .chain-rods:after {
    content"";
    height70px;
    width6px;
    background#666;
    position: absolute;
    transformrotate(240deg);
    -webkit-transformrotate(240deg);
    -moz-transformrotate(240deg);
   }
   .outer-axle {
    height70px;
    width70px;
    border-radius50%;
    background: transparent;
    border5px solid #666;
    position: absolute;
    margin62px 0 0 226px;
    z-index3;
   }
   
   .outer-axle:after {
    content"";
    height74px;
    width74px;
    border-radius50%;
    background: transparent;
    border5px dotted #666;
    margin: -7px;
    position: absolute;
    z-index3;
    animation: wheel-rotate 2s linear infinite;
   }
   /*车链子*/
   .chain-up {
    background-color: transparent;
    background-size8px 2px;
    background-position0 030px 30px;
    width155px;
    height4px;
    position: absolute;
    z-index9;
    background#EEE;
    transformrotate(-11deg);
    margin76px 0 0 98px;
   }
   .chain-up:before {
    content"";
    background-color: transparent;
    background-imagelinear-gradient(90deg#666 25%, transparent 25%, transparent 75%#666 75%#666);
    background-size8px 2px;
    background-position0 030px 30px;
    width155px;
    height4px;
    animation: chainUp 2s linear infinite;
    position: absolute;
    z-index10;
   }
   .chain-bottom {
    background-color: transparent;
    background-size8px 2px;
    background-position0 030px 30px;
    width155px;
    height4px;
    position: absolute;
    z-index9;
    background#EEE;
    -webkit-transformrotate(9deg);
    -moz-transformrotate(9deg);
    transformrotate(9deg);
    margin127px 0 0 98px;
   }
   
   .chain-bottom:before {
    content"";
    background-color: transparent;
    background-imagelinear-gradient(90deg#666 25%, transparent 25%, transparent 75%#666 75%#666);
    background-size8px 2px;
    background-position0 030px 30px;
    width155px;
    height4px;
    animation: chainDown 2s linear infinite;
    position: absolute;
    z-index10;
   }
   /*脚踏*/
   .pedal-rod {
    height120px;
    width6px;
    background#666;
    position: absolute;
    margin: -25px 0 0 0px;
   }
   
   .pedal-rod:before {
    width40px;
    height10px;
    background#666;
    position: absolute;
    margin10px;
    content"";
    margin: -7px -17px;
    animation: pedal1 2s linear infinite;
   }
   
   .pedal-rod:after {
    width40px;
    height10px;
    background#666;
    position: absolute;
    margin10px;
    content"";
    margin119px -17px;
    animation: pedal2 2s linear infinite;
   }
   /*水壶架*/
   .bottle-holder {
    width20px;
    height36px;
    background#daeded;
    border3px solid #5E999B;
    position: absolute;
    margin54px 0 0 -25px;
   }
   
   .bottle-holder:after {
    width20px;
    height3px;
    content"";
    background#5E999B;
    position: absolute;
    margin24px 0 0 0px;
   }
   /*水壶*/
   .bottle-holder:before {
    background-color#daeded;
    width18px;
    height10px;
    border-radius30% / 100%;
    border-bottom-left-radius0;
    border-bottom-right-radius0;
    content"";
    position: absolute;
    margin-top: -13px;
    border1px solid #98baba;
    border-bottom0;
   }
   .bottle-holder span {
    position: absolute;
    width9px;
    height4px;
    background#666;
    margin: -17px 0 0 5px;
   }
   /*车链子动画*/
   @keyframes chainUp {
    0% {
     background-position0 25%;
    }
    100% {
     background-position100% 0;
    }
   }
   @keyframes chainDown {
    0% {
     background-position100% 0;
    }
    100% {
     background-position0 25%;
    }
   }
   /*脚踏动画*/
   @keyframes pedal1 {
    0% {
     transformrotate(00deg);
    }
    25% {
     transformrotate(-140deg);
    }
    50% {
     transformrotate(-180deg);
    }
    75% {
     transformrotate(-240deg);
    }
    100% {
     transformrotate(-360deg);
    }
   }
   @keyframes pedal2 {
    0% {
     transformrotate(00deg);
    }
    25% {
     transformrotate(-60deg);
    }
    50% {
     transformrotate(-180deg);
    }
    75% {
     transformrotate(-340deg);
    }
    100% {
     transformrotate(-360deg);
    }
   }
  </style>
 </head>

 <body>
  <div class="cycle-outer">
   <div class="cycle-wrapper">
    <!--
                 描述:车架
                -->
    <div class="cycle-body">
     <div class="seat">
      <span></span>
     </div>
     <div class="front-wheel-frame"></div>
     
     <div class="top-frame"></div>
     <div class="front-frame">
      <div class="bottle-holder">
       <span></span>
      </div>
     </div>
     <div class="center-frame"></div>
     <div class="back-frame"></div>
     <div class="bottom-frame"></div>
     <div class="handlebar-front"></div>
     <div class="handlebar-curve"></div>
    </div>
    <!--
                 描述:后轮
                -->
    <div class="cycle-wheel cycle-wheel-back">
     <div class="cycle-wheel-outer">
      <div class="cycle-wheel-inner">
       <div class="cycle-wheel-inner-padding">
        <ul class="spoke-container">
         <li class="spoke"></li>
         <li class="spoke"></li>
        </ul>
        <div class="inner-disc"></div>
        <div class="inner-disc-2"></div>
       </div>
      </div>
     </div>
    </div>
    <!--
                 描述:前轮
                -->
    <div class="cycle-wheel cycle-wheel-front">
     <div class="cycle-wheel-outer">
      <div class="cycle-wheel-inner">
       <div class="cycle-wheel-inner-padding">
        <ul class="spoke-container">
         <li class="spoke"></li>
         <li class="spoke"></li>
        </ul>
        <div class="inner-disc"></div>
        <div class="inner-disc-2"></div>
       </div>
      </div>
     </div>
    </div>
    <!--
                 描述:中心轴  车链子 牙盘 水壶架  水壶   脚踏
                -->
    <div class="chain-up"></div>
    <div class="chain-bottom"></div>
    <div class="chain-rotation">
     <div class="outer-axle"></div>
     <div class="chain-disc-outer">
      <div class="chain-disc-inner"></div>
     </div>

    </div>
    <div class="chain-rods">
     <div class="pedal-rod"></div>
    </div>
   </div>
  </div>

  <div style="text-align:center;clear:both;">
 </body>

</html>

以上是“如何利用纯CSS3实现动态的自行车特效”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

原文链接:https://www.jb51.net/css/528551.html

AI

开发者交流群×