美文网首页
CSS3中的动画功能

CSS3中的动画功能

作者: 秋枫残红 | 来源:发表于2017-11-12 15:47 被阅读0次

在CSS3中主要依靠transitions和animations实现动画功能

Transtions

  • 主要用法
    transitions:property duration timing-function
  • property表示要更改的属性,duration表示更改所用时间,timing-function表示过渡方式,一般使用linear使用相同时速度平滑过渡,举个栗子
div{
    position: absolute;
    left:10px;
    width: 100px;
    background-color: red;
    -webkit-transition: left 2s linear;
}
div:hover{
    left:200px;
}
  • 也可以将这个属性拆分来写
div{
    position: absolute;
    left:10px;
    width: 100px;
    background-color: red;
    -webkit-transition-property: left;
    -webkit-transition-duration: 2s;
    -webkit-transition-timing-function: linear ;
}
div:hover{
    left:200px;
}
  • 也可以使用该属性值同时过渡多个值
div{
    position: absolute;
    left:10px;
    width: 100px;
    background-color: red;
    -webkit-transition: left 2s linear,background-color 2s linear;
}
div:hover{
    left:200px;
    background-color: darkblue;
}

Animations

  • animations与属性transitions最大的区别就是animations通过定义多个关键帧来实现更加复杂的动画,举个例子
div {
    position: absolute;
    left:10px;
    width:200px;
    background-color: red;
}

@-webkit-keyframes mycolor {
    0% {
        left: 10px;
        background-color: red;
    }
    25% {
        left:200px;
        background-color: darkblue;
    }
    50% {
        left: 400px;
        background-color: yellow;
    }
    75%{
        left: 200px;
        background-color: darkblue;
    }
    100% {
        left:10px;
        background-color: red;
    }
}

div:hover {
    -webkit-animation: mycolor 5s linear;
    -webkit-animation-iteration-count: infinite;
}
  • firefox使用@-moz-keyframes定义关键帧

实现动画的方法

方法 描述
linear 动画速度保持不变
ease-in 先慢后快
ease-out 先快后慢
ease 慢-快-慢
ease-in-out 同上

相关文章

  • CSS3动画

    动画是CSS3中新增功能,CSS3中动画分为两种,分别是transitions和animations,transi...

  • 08_dayCSS动画

    CSS3新增的功能有:过渡和动画,阴影和圆角 css3过渡动画: css3都有哪些新增的东西 : 过度,动画,阴影...

  • 07day

    CSS3动画 CSS3 @keyframes 规则如需在 CSS3 中创建动画,您需要学习 @keyframes ...

  • CSS3中的动画功能

    在CSS3中主要依靠transitions和animations实现动画功能 Transtions 主要用法tra...

  • web前端入门到实战:CSS3中的变形(transform)、过

    css3中制作动画的几个属性:css3中的变形(transform)、过渡(transition)、动画(anim...

  • web前端入门到实战:CSS3中的变形(transform)、过

    css3中制作动画的几个属性:css3中的变形(transform)、过渡(transition)、动画(anim...

  • CSS3 中的动画功能

    Transitions功能 平滑过渡语法: Animations功能 实现多个值同时改变的动画

  • CSS3动画

    在CSS3中,动画效果使用animation属性来实现。animation属性和transition属性功能是相同...

  • 读Zepto源码之Fx模块

    fx 模块为利用 CSS3 的过渡和动画的属性为 Zepto 提供了动画的功能,在 fx 模块中,只做了事件和样式...

  • 2018-08-15

    CSS动画 CSS3 @keyframes 规则如需在 CSS3 中创建动画,您需要学习 @keyframes 规...

网友评论

      本文标题:CSS3中的动画功能

      本文链接:https://www.haomeiwen.com/subject/pjrgmxtx.html