CSS3-过渡动画(transition & animation)

目前在CSS3中使用动画效果有两种途径:
transitionanimation

1.transition
主要属性:
transition-delay 过渡动画延迟时间
transition-duration 过渡动画持续时间
transition-timing-function:linar 过渡变化曲线图

实例:

<!DOCTYPE html>
<html>

<head>
    <meata charset="UTF-8" />
    <title>MelanceXin TransitionCSS_Test</title>
    <style type="text/css">
        p{
            width:100px;
            height:100px;
            background-color:antiquewhite;	
        }
        p:hover{				
            /* 指定动作 */
            width:200px;
            height:200px;
            background-color: #50f06a;
            transition-delay: 200ms;					
            /* CSS3.0新增属性, 过渡效果-延时 */
            transition-duration:500ms;				
             /* 过渡效果-变化过程持续时间  (目前几乎新版的浏览器的都支持,但考虑到用户可能会使用老版本的浏览器,建议使用带上前标的transition) */
              /* -webkit-transition-duration:500ms;	   */
             /* -webkit- 表示适用于 Google 和 safari 浏览器 */
             /* -o-transition-duration:500ms;			 */
              /* -o- 表示 opera 浏览器 */
             /* -moz-transition-duration:500ms;			 */
             /* -moz- 表示 火狐浏览器 */
             transition-property:background-color,width,height; 		
             /* 表示需要进行过渡效果的属性 */
             transition-timing-function:linar ;   
              /* 属性值linar,ease ,ease-in ,ease-out,ease-in-out   分别对应贝塞尔曲线不同的曲线变化效果  */
        }
</style>
</head>

<body>

    <body>
           <p></p>
    </body>
</body>

</html>

实现效果图:
在这里插入图片描述

2.animation
主要属性:
animation-duration 一次动画从开始到结束持续多长时间
animation-delay 延迟多少时间开始动画
animation-name 动画名
animation-iteration-count 设置动画播放次数,属性值为 infinite 表示无限次重复播放该动画
animation-direction: alternate 设置动画播放方式,属性值为 alternate 表示animation正反向交替运行
etc…

实例:(变大缩小动画 to…from )

<!DOCTYPE html>
<html>
<head>
    <meata charset="UTF-8" />
    <title>MelanceXin AnimationCSS_Test</title>
    <style type="text/css">
        p {
            width: 100px;
            height: 100px;
            background-color: antiquewhite;
        }
        p:hover {
            /* 指定动作 */
            animation-duration: 1000ms;
            animation-delay: 200ms;
            animation-name: MelanceXin;
            /* 这里MelanceXin为动画名 */
            animation-iteration-count: infinite;
            /* 属性值为 infinite 表示无限次重复播放该动画 */
            animation-direction: alternate;
            /* 属性值为 alternate 表示animation正反向交替运行 */
        }

        @keyframes MelanceXin
        /* 定义对应动画名的动画 */
            {
            to {
                width: 200px;
                height: 200px;
                background-color: #ffad2a;
            }

            from {
                width: 100px;
                height: 100px;
                background-color: #40a1ce;
            }
        }
    </style>
</head>

<body>
    <p></p>
</body>

</html>

实现效果图:

在这里插入图片描述

实例2:(在animation 中设立多个断点)

<!DOCTYPE html>
<html>
<head>
    <meata charset="UTF-8" />
    <title>MelanceXin AnimationCSS_Test</title>
    <style type="text/css">
        p{
					width:100px;
					height:100px;
					background-color:antiquewhite;	
				}
				p:hover{				
                    /* 指定动作 */
					animation-duration:2000ms;
					animation-delay:200ms;
					animation-name:MelanceXin;	  
                    /* 这里MelanceXin为动画名 */
					animation-iteration-count:2;  	
                    /* 属性值为 1. infinite 表示无限次重复播放该动画    2.数字,表示重复的次数 */
					animation-direction:alternate;   
                      /* 属性值为 alternate 表示animation正反向交替运行 */
				}
				@keyframes MelanceXin			
                /* 定义对应动画名的动画 */
				{
				from{
						width:100px;
						height:100px;
						background-color:#fffec3;
						}
				
					50%{
						width:120px;
						height:200px;
						background-color:#3b88ff;
						}
					75%{
						width:200px;
						height:120px;
						background-color:#7fe444;
						}
					to{
						width:200px;
						height:200px;
						background-color:#ffad2a;
						}
				}
    </style>
</head>

<body>
    <p></p>
</body>

</html>

实现效果图:
在这里插入图片描述

动画和过渡效果的区别:
1.动画必须完整整次,如果是执行一次,结束时会回到最初始状态。
2.过渡动画则不用,过渡效果结束时会停在设定的状态上。
3.动画效果使用比较复杂,需要用到一个名为animation-name的属性

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
CSS3的变形(transform)、过渡(transition)、动画(animation)是CSS3中非常重要的特性,可以为网页设计带来更加丰富的交互效果和视觉体验。 1. 变形(transform) 变形是指通过CSS3中的transform属性对元素进行平移、旋转、缩放、倾斜等操作,从而改变元素的形状和位置。具体的变形方式包括: 平移(translate):移动元素的位置。 旋转(rotate):以元素中心点为轴心进行旋转。 缩放(scale):缩放元素的大小。 倾斜(skew):倾斜元素。 矩阵变形(matrix):通过矩阵变换实现复杂的变形效果。 示例代码: ``` div { transform: translate(50px, 50px); } ``` 2. 过渡(transition) 过渡是指在元素属性改变时,通过CSS3中的transition属性设置过渡时间和过渡效果,从而实现平滑的转换效果。具体的过渡方式包括: 过渡时间(transition-duration):设置过渡动画的时间,单位可以是秒(s)或毫秒(ms)。 过渡效果(transition-timing-function):设置过渡效果,常用的有linear、ease-in、ease-out、ease-in-out等。 过渡属性(transition-property):设置需要过渡的属性,可以是单个属性或多个属性。 过渡延迟(transition-delay):设置过渡动画的延迟时间。 示例代码: ``` div { transition: all 1s ease-in-out; } ``` 3. 动画(animation) 动画是指通过CSS3中的animation属性对元素进行动画效果的设置。具体的动画方式包括: 关键帧动画(@keyframes):定义一组动画序列,可以设置元素在不同时间点上的样式。 动画时间(animation-duration):设置动画持续时间,单位可以是秒(s)或毫秒(ms)。 动画速度(animation-timing-function):设置动画速度,常用的有linear、ease-in、ease-out、ease-in-out等。 动画延迟(animation-delay):设置动画延迟时间。 动画方向(animation-direction):设置动画播放方向,可以是正方向(normal)、反方向(reverse)、交替播放(alternate)等。 动画次数(animation-iteration-count):设置动画播放次数,可以是无限次(infinite)。 示例代码: ``` div { animation: myanimation 2s ease-in-out infinite; } @keyframes myanimation { 0% { transform: scale(1); } 50% { transform: scale(1.5); } 100% { transform: scale(1); } } ``` 以上就是CSS3中变形、过渡动画的基本介绍和示例代码,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MelanceXin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值