• Transitions功能使用方法

在css3中,transitions功能通过将元素的某个属性从一个属性值在指定的时间内平滑过渡到另一个属性值来实现动画功能,可通过transitions属性来使用transitions功能。

transitions属性的使用方法如下所示:

transitions:property durantion timing-function

其中property表示对哪个属性进行平滑过渡,duration表示在多长时间内完成属性值的平滑过渡,timing-function表示通过什么方法来进行平滑过渡。例子如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Transitions功能的使用示例</title>
<style>
div{
background-color: #ffff00;
-webkit-transition: background-color 1s linear;
-moz-transition: background-color 1s linear;
-o-transition: background-color 1s linear;
}
div:hover{
background-color: #00ffff;
}
</style>
</head>
<body>
<div>示例文字</div>
</body>
</html>

在CSS3中,还有另外一种使用transitions功能的方法,就是将transitions属性中的三个参数改写成transition-property属性、transition-duration属性、transition-timing-function属性,这三个属性的含义及属性值的指定方法与transitions属性中的三个参数的含义及指定方法完全相同。

  • 使用transitions功能同时对多个属性值进行平滑过渡多个属性值

可以使用transitions功能同时对多个属性值进行平滑过渡,例子如下:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>使用transitions功能实现多个属性的平滑过渡</title>

    <style>

        div {

            background-color: #ffff00;

            color: #000000;

            width: 300px;

            -webkit-transition: background-color 1s linear, color 1s linear, width 1s linear;

            -moz-transition: background-color 1s linear, color 1s linear, width 1s linear;

            -o-transition: background-color 1s linear, color 1s linear, width 1s linear;

        }

        div:hover {

            background-color: #003366;

            color: #ffffff;

            width: 400px

        }

    </style>

</head>

<body>

<div>示例文字</div>

</body>

</html>
  • Animations功能的使用方法

Animations功能与transitions功能相同,都是通过改变元素的属性值来实现动画效果的,它们的区别在于:使用transitions功能时只能通过指定属性的开始值与结束值,然后在这两个属性值之间进行平滑过渡的方式来实现动画效果,因此不能实现比较复杂的动画效果;例子如下:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>animations功能的使用示例</title>

    <style>

        div {

            background-color: red;

        }

        @-webkit-keyframes mycolor {

            0% {

                background-color: red;

            }

            40% {

                background-color: darkblue;

            }

            70% {

                background-color: yellow;

            }

            100% {

                background-color: red;

            }

        }

        div:hover{

            -webkit-animation-name:mycolor;

            -webkit-animations-duration:5s;

            -webkit-animation-timing-function: linear;

            animation-name:mycolor;

            animation-duration: 5s;

            animation-timing-function: linear;

        }

    </style>

</head>

<body>

<div>示例文字</div>

</body>

</html>
  • 实现多个属性值同时改变的动画
<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>让多个属性同时变化</title>

    <style>

       div{

           position: absolute;

           background-color:yellow;

           top: 100px;

           width: 500px;

       }

        @keyframes mycolor {

            0%{

                background-color: red;

                transform: rotate(0deg);

            }

            40%{

                background-color: darkblue;

                transform: rotate(30deg);

            }

            70%{

                background-color: yellow;

                transform: rotate(-30deg);

            }

            100%{

                background-color: red;

                transform: rotate(0deg);

            }

        }

        div:hover{

            animation-name:mycolor;

            animation-duration: 5s;

            animation-timing-function: linear;

        }

    </style>

</head>

<body>

<div>示例文字</div>

</body>

</html>

可以通过animation-iteration-count属性来指定动画的播放次数,也可以通过对该属性指定infinite属性值让动画不停地循环播放。

  • 实现动画的方法

Animations功能中实现动画的方法:

linear 在动画开始时到结束时以同样的速度进行改变

ease-in 动画开始时速度很慢,然后速度沿曲线值进行加快

ease-out 动画开始时速度很快,然后速度沿曲线值进行放慢

ease   动画开始时速度很慢,然后速度沿曲线值进行加快,然后沿曲线值放慢

ease-in-out 动画开始时速度很慢,然后速度沿曲线值进行加快,然后再沿曲线值放慢

  • 实现网页的淡入效果
<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>实现网页淡入效果的示例</title>

    <style>

     @keyframes fadein {

         0%{

             opacity:0;

             background-color: white;

         }

         100%{

             opacity: 1;

             background-color: white;

         }

     }

        body{

            animation-name:fadein;

            animation-duration: 5s;

            animation-timing-function: linear;

            animation-iteration-count: 1;

        }

    </style>

</head>

<body>

<div>示例文字</div>

</body>

</html>

CSS3学习系列之动画的更多相关文章

  1. [CSS3] 学习笔记-CSS动画特效

    在CSS3中,出现了很多出彩的效果,例如2D.3D以及过度.动画和多列等.这些效果为页面设计添加了很多的可选设计. 1.2D.3D转换 转换,是使元素改变尺寸.形状.位置的一种效果:通过CSS3转换, ...

  2. css3学习系列之选择器(一)

    CSS3中的属性选择器 [att*=val]属性选择器:[att*=val]属性选择器的含义是:如果元素att表示的属性之属性值中包含用val指定的字符的话,则该元素使用这个样式. [att^=val ...

  3. CSS3学习系列之选择器(二)

    first-child选择器和last-child选择器 first-child指定第一个元素.last-child指定最后一个子元素. 例如: <!DOCTYPE html> <h ...

  4. CSS3学习系列之选择器(四)

    使用选择器来插入文字 css2中,使用before选择器在元素前面插入内容,使用after选择器在元素后面插入内容,在选择器的content属性中定义要插入的内容.将content属性值设定为none ...

  5. CSS3学习系列之字体

    给文字添加阴影 在CSS3中,可以使用text-shadow属性给页面上的文字添加阴影效果.text-shadow属性是在css2中定义的,在css2.1中删除,在css3的text模块中有恢复了,用 ...

  6. CSS3学习系列之盒样式(一)

    盒的基本类型 在css中,使用display属性来定义盒的类型,总体上来说,css中的盒分为block类型与inline类型 inline-block类型 inline-block类型是在css2.1 ...

  7. CSS3学习系列之盒样式(二)

    text-overflow属性 当通过把overflow属性的属性值设定为"hidden"的方法,将盒中容纳不下的内容隐藏起来时,如果使用text-overflow属性,可以在盒的 ...

  8. CSS3学习系列之背景相关样式(一)

    新增属性: background-clip:指定背景的显示范围 background-origin:指定绘制背景图像时的起点 background-size:指定背景中图像的尺寸 background ...

  9. CSS3学习系列之背景相关样式(二)

    在border-radius属性中指定两个半径 在border-radius属性中,可以指定两个半径,指定方法如下所示: border-radius:40px 20px; 针对这种情况,各种浏览器的处 ...

随机推荐

  1. 【JAVAWEB学习笔记】04_JavaScript

    晨读单词: onmouseover:鼠标移入 onmouseout:鼠标移出 attribute:属性 node:节点 document:文档 element:元素 textNode:文本节点 app ...

  2. Hibernate参数绑定的五种方式

    Hibernate参数绑定 参数绑定优点: (1)安全性 防止用户恶意输入条件和恶意调用存储过程 (2)提高性能 底层采用JDBC的PreparedStatement预定义sql功能,后期查询直接从缓 ...

  3. Word Ladder 2015年6月3日

    Given two words (beginWord and endWord), and a dictionary, find the length of shortest transformatio ...

  4. 笔记本shift变粘贴,粘滞键设置已关闭

    之前手贱吧,拿湿抹布擦了擦笔记本电脑的自带键盘,然后部分按键失灵了. 本想着反正也都是在寝室用的,趁机找借口买了个机械键盘,啪啪啪... 刚开始好好的,后来发现一按shift就会粘贴,百度了下都说是粘 ...

  5. 走进javascript——数组的那些事

    Array构造器 如果参数只有一个并且是Number类型,那么就是指定数组的长度,但不能是NaN,如果是多个会被当做参数列表. new Array(12) // (12) [undefined × 1 ...

  6. 使用babel编译es6

    起因:开发中慢慢的学习使用es6,但是JavaScript需要浏览器来解析,而不是所有浏览器都支持es6,所以为了兼容es6,需要第三方工具进行编译es6. 工具:node,gulp,gulp-bab ...

  7. 挂载mount

    mount 1 挂载mount 基本概念 挂载:将额外文件系统与根文件系统现存的目录建立起关联关系,进而使得此目录做为其它文件访问入库的行为 卸载:为解除关联关系的过程 注意:挂载点下原有的文件在挂载 ...

  8. Coursera 机器学习笔记(七)

    主要为第九周内容:异常检测.推荐系统 (一)异常检测(DENSITY ESTIMATION) 核密度估计(kernel density estimation)是在概率论中用来估计未知的密度函数,属于非 ...

  9. 使用r.js来打包模块化的javascript文件

    前面的话 r.js(下载)是requireJS的优化(Optimizer)工具,可以实现前端文件的压缩与合并,在requireJS异步按需加载的基础上进一步提供前端优化,减小前端文件大小.减少对服务器 ...

  10. 将某个日期字符串转换为java.sql.Date的类型

    import java.text.ParseException; import java.text.SimpleDateFormat; public class date { /** * @param ...