资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

如何使用CSS3实现动画效果

这篇文章主要为大家展示了“如何使用CSS3实现动画效果”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何使用CSS3实现动画效果”这篇文章吧。

站在用户的角度思考问题,与客户深入沟通,找到上思网站设计与上思网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:做网站、成都做网站、企业官网、英文网站、手机端网站、网站推广、空间域名、虚拟空间、企业邮箱。业务覆盖上思地区。

浏览器支持

Internet Explorer 10、Firefox 以及 Opera 支持 animation 属性。

Safari 和 Chrome 支持替代的 -webkit-animation 属性。

注释:Internet Explorer 9 以及更早的版本不支持 animation 属性。

定义和用法

animation属性是一个简写属性,用于设置六个动画属性:

  • animation-name

  • animation-duration

  • animation-timing-function animation-delay

  • animation-iteration-count animation-direction

语法

animation: name duration timing-function delay iteration-count direction;
描述备注
animation-timing-function规定动画的速度曲线可取值为 linear ,ease(淡入淡出),ease-in,ease-out ,ease-in-out,cubic-bezier(n, n, n, n)
animation-play-state规定动画是否正在运行或暂停。paused 表示暂停状态,running 表示运行状态
animation-name规定需要绑定到选择器的 keyframe 名称@keyframe { from {opcity:0} to {opcity:1}}
animation-iteration-count规定动画应该播放的次数可选值为   infinite(无限次)n(比如 5 次)
animation-fill-mode动画在播放之前或之后,其动画效果是否可见。none(默认) / forwards(动画完成后) / backwards(在动画显示之前) / both(两者);
animation-duration规定完成动画所花费的时间,以秒或毫秒计必须规定否则,不执行动画
animation-direction规定是否应该轮流反向播放动画默认值 normal,alternate 为动画应该轮流反向播放。左右左
animation-delay规定在动画开始之前的延迟定义动画开始前等待的时间,以秒或毫秒计。默认值是 0。单位为 s

关于keyframe的定义

  • Firefox支持替代的@-moz-keyframes规则;

  • Opera支持替代的@-o-keyframes规则;

  • Safari和Chrome支持替代的@-webkit-keyframes规则;

  • 取值支持 0-100% 和from,to。

@keyframes move {
  0% {
    top: 0px;
    left: 0px;
  }
  25% {
    top: 200px;
    left: 200px;
  }
  50% {
    top: 100px;
    left: 100px;
  }
  75% {
    top: 200px;
    left: 200px;
  }

  100% {
    top: 0px;
    left: 0px;
  }
}

@keyframes move {
  from {
    top: 0px;
    left: 0px;
  }
  to {
    top: 0px;
    left: 100px;
  }
}

demo 写了一个例子,地球绕太阳转

如何使用CSS3实现动画效果

以下是代码



  
    
  
/* css 部分 */
@keyframes t {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@-webkit-keyframes t {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.t {
  height: 500px;
  width: 500px;
  position: relative;
  border-radius: 50%;
  transform: scale(.8);
  border: 1px solid #dedede;
  &::before {
    content: "";
    width: 50px;
    height: 50px;
    background: radial-gradient(72px, #f00, #ff0, #080);
    border-radius: 50%;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-top: -25px;
    margin-left: -25px;
    box-shadow: 0 0 37px #fcff4a;
  }
  .t1 {
    height: 20px;
    border-radius: 50%;
    width: 20px;
    margin-top: -10px;
    top: 50%;
    left: -10px;
    background: radial-gradient(26px, #0082ff, #184608, #003ade);
    position: absolute;
    animation: t 3s infinite linear;
    transform-origin: 260px center;
  }
}

以上是“如何使用CSS3实现动画效果”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!


网页标题:如何使用CSS3实现动画效果
分享网址:http://cdkjz.cn/article/jcjojs.html
返回首页 了解更多建站资讯
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220