微信公众号
扫描关注微信公众号
博客大厅

CSS3动画代码集合

原创 来源:博客站 阅读 0 01月21日 13:55 听全文

CSS3动画是一种使用CSS(层叠样式表)中的属性和选择器来创建动画效果的技术。以下是一些CSS3动画的代码示例,涵盖了不同的动画效果:

淡入淡出动画

@keyframes fadeInOut {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.box {
  display: block;
  width: 100px;
  height: 100px;
  background-color: orange;
  border-radius: 50%;
  animation-name: fadeInOut;
  animation-duration: 3s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
}

旋转动画

@keyframes rotateAnimation {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.box {
  margin-top: 200px;
  width: 100px;
  height: 100px;
  background-color: orange;
  animation: rotateAnimation 2s linear infinite;
}

弹跳动画

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-200px);
  }
  60% {
    transform: translateY(-15px);
  }
}

.box {
  margin-top: 200px;
  width: 100px;
  height: 100px;
  background-color: orange;
  animation: bounce 2s infinite;
}

颜色渐变动画

@keyframes colorChange {
  0% {
    background-color: orange;
  }
  50% {
    background-color: skyblue;
  }
  100% {
    background-color: lightblue;
  }
}

.box {
  margin-top: 200px;
  width: 100px;
  height: 100px;
  background-color: orange;
  animation: colorChange 5s infinite;
}

摇晃动画

.shake {
  width: 40px;
  height: 40px;
  display: block;
  background: lightgreen;
  border-radius: 50%;
  margin: 5px;
  color: #fff;
  font-size: 24px;
  text-align: center;
  line-height: 40px;
  cursor: pointer;
  transition: all 0.25s;
}

.shake:hover {
  animation: shake 0.25s;
  background: lightblue;
}

@keyframes shake {
  0%, 10%, 55%, 90%, 94%, 98%, 100% {
    transform: scale(1, 1);
  }
  30% {
    transform: scale(1.14, 0.86);
  }
  75% {
    transform: scale(0.92, 1.08);
  }
  92% {
    transform: scale(1.04, 0.96);
  }
  96% {
    transform: scale(1.02, 0.98);
  }
  99% {
    transform: scale(1.01, 0.99);
  }
}

搜索栏宽度变化动画

.search {
  width: 80px;
  height: 40px;
  border-radius: 40px;
  border: 2px solid lightblue;
  position: absolute;
  right: 200px;
  outline: none;
  text-indent: 12px;
  color: #666;
  font-size: 16px;
  padding: 0;
  transition: width 0.5s;
}

.search:focus {
  width: 200px;
}

这些代码示例展示了如何使用CSS3的@keyframes规则、animation属性、transition属性以及transform属性来创建各种动画效果。你可以根据这些示例代码进行自定义和扩展,以适应你的网页设计和开发需求。同时,请注意在实际应用中考虑动画的兼容性、性能优化以及用户体验。

学在每日,进无止境!更多精彩内容请关注微信公众号。
原文出处: 内容由AI生成仅供参考,请勿使用于商业用途。如若转载请注明原文及出处。
出处地址:http://www.07sucai.com/tech/148.html
版权声明:本文来源地址若非本站均为转载,若侵害到您的权利,请及时联系我们,我们会在第一时间进行处理。
>