温馨提示×

温馨提示×

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

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

html如何实现毛毛虫爬行动画

发布时间:2020-09-29 16:47:59 来源:亿速云 阅读:135 作者:小新 栏目:web开发

这篇文章主要介绍了html如何实现毛毛虫爬行动画,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

毛毛虫儿时大家都有见过,今天想起来写一个爬行的动作,具体代码如下所示:

html代码:

<p class='container'>
  <p class='hide left'></p>
  <p class='hide right'></p>
  <p class='hide bottom'></p>
  <p class='circle-container'>
    <p class='circle'></p>
  </p>
</p>

css代码:

 <style>
body {
  background-color: #1B6CB2;
  margin: 0;
}
.container {
  position: absolute;
  width: 600px;
  height: 400px;
  overflow: hidden;
  top: 50%;
  left: 60%;
  transform: translate(-50%, -50%);
}
.hide {
  height: 100%;
  width: 150px;
  background: #1B6CB2;
  position: absolute;
  z-index: 2;
}
.hide.left {
  left: 0;
}
.hide.right {
  right: 0;
}
.hide.bottom {
  bottom: 0;
  width: 100%;
  height: 50%;
}
.circle {
  position: absolute;
  height: 75px;
  width: 150px;
  border: 3px solid white;
  border-radius: 50%/100% 100% 0 0;
  border-bottom: none;
  top: 40%;
  left: 50%;
  transform-origin: 0% 50%;
  transform: translate(-50%, -50%);
  animation: magic 1.8s ease infinite;
}
@keyframes magic {
  0% {
    transform: rotate(-170deg) translate(-50%, -50%);
  }
  50% {
    transform: rotate(0deg) translate(-50%, -50%);
  }
  100% {
    transform: rotate(180deg) translate(-50%, -50%);
  }
}
.circle-container {
  position: absolute;
  height: 75px;
  width: 150px;
  top: 40%;
  left: 50%;
  transform-origin: 0% 50%;
  transform: translate(-50%, -50%);
  animation: power 1.8s ease-out infinite;
}
@keyframes power {
  0% {
    margin-left: 20px;
  }
  50% {
    margin-left: -55px;
  }
  99.9% {
    margin-left: -130px;
  }
  100% {
    margin-left: 20px;
  }
}
  </style>

感谢你能够认真阅读完这篇文章,希望小编分享html如何实现毛毛虫爬行动画内容对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,遇到问题就找亿速云,详细的解决方法等着你来学习!

向AI问一下细节

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

AI