html&css系列学习——(六)过渡及动画

目录

一、过渡 transition(手动触发)

 1. 过渡触发方式       

2. 过渡要素 

3. 过渡连写 

二、动画 animation(自动执行)

1.动画属性

2.动画关键帧

3. 动画连写

4.动画引入

总结


一、过渡 transition(手动触发)

 1. 过渡触发方式       

触发方法描述
:hover{}鼠标悬停时触发
:active{}单击元素并按住鼠标时触发
:focus{}获得焦点时触发
@media触发符合媒体查询条件时触发
点击事件点击元素时触发 

2. 过渡要素 

要素描述取值
transition-property过渡属性none
all
property
transition-duration过渡持续时间time(s),默认0
transition-timing-function过渡速度linear:相同速度从一而终(==cubic-bezier(0,0,1,1) )
ease:先慢再快,最后慢(==cubic-bezier(0.25,0.1,0.25,1) )
ease-in:先慢后匀速(==cubic-bezier(0.42,0,1,1) )
ease-out:先匀速后慢(==cubic-bezier(0,0,0.58,1) )
ease-in-out:先慢再匀速,后慢(cubic-bezier(0.42,0,0.58,1) )
steps(int,start|end):参数:函数的间隔数,动画是从时间段的开头连续还是末尾连续
cubic-bezier(n,n,n,n):自定义速度,n取0~1
transition-delay过渡等待时长time(s),默认0

3. 过渡连写 

transition: 过渡属性 过渡时长 运动速度 延迟时间;

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
            background-color: orange;
            transition: width 1s linear 0s,height 2s linear 0s,background-color 2s linear 0s;
        }
        div:hover{width:200px;height:400px;background-color: orangered;}
    </style>
</head>
<body>
    <div></div>
</body>
</html>

 

二、动画 animation(自动执行)

1.动画属性

属性描述取值
animation-name动画名称
animation-duration动画持续时长time,默认为0
animation-timing-function动画速度曲线linear:相同速度从一而终(==cubic-bezier(0,0,1,1) )
ease:先慢再快,最后慢(==cubic-bezier(0.25,0.1,0.25,1) )
ease-in:先慢后匀速(==cubic-bezier(0.42,0,1,1) )
ease-out:先匀速后慢(==cubic-bezier(0,0,0.58,1) )
ease-in-out:先慢再匀速,后慢(cubic-bezier(0.42,0,0.58,1) )
steps(int,start|end):参数:函数的间隔数,动画是从时间段的开头连续还是末尾连续
cubic-bezier(n,n,n,n):自定义速度,n取0~1
animation-delay动画等待时长time(s)
animation-iteration-count:动画播放次数n  n次
infinite  无限次
animation-direction动画是否反向播放normal  (默认),往返动画
alternate  反向执行
animation-fill-mode动画结束状态none  不做任何改变
forwards  让元素结束状态保持动画最后一帧的样式
backwards  让元素等待状态的时候显示动画第一帧的样式
both  让元素等待显示动画第一帧, 结束保持动画最后一帧
animation-play-state动画是否暂停running 继续
paused 暂停

2.动画关键帧

  格式:

@keyframs name{
        //开始 中间过程 结束状态
        0%{}
        25%{}
        50%{}
        100%{}
    }

3. 动画连写

animation:动画名称(animation-name) 动画时长(animation-duration) 动画运动速度(animation-timing-function) 延迟时间(animation-delay) 执行次数(animation-iteration-count) 往返动画(animation-direction);

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<style>
		div{
			width: 100px;
			height: 100px;
			background-color:pink;
			animation: leftToRight 1s linear 0s infinite alternate forwards;
		}
		div:hover{
			/* 设置动画是否暂停 paused暂停*/
			animation-play-state: paused;
		}
		/* 动画关键帧 */
		@keyframes leftToRight {
			0%{
				height: 100px;
                width: 100px;
			}
			25%{
				height: 150px;
                width: 120px;
			}
			50%{
				height: 250px;
                width: 150px;
			}
			100%{
				height: 400px;
                width: 200px;
			}
		}
	</style>
</head>
<body>
	<div></div>
</body>
</html>

4.动画引入

引入css动画样式:Animate.css | A cross-browser library of CSS animations.

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"
/>
</head>
<body>
	<h1 class="animate__animated animate__bounce">An animated element</h1>
	<h1 class="animate__animated animate__wobble">An animated element</h1>
	<h1 class="animate__animated animate__backInRight">An animated element</h1>
	<h1 class="animate__animated animate__bounceIn">An animated element</h1>

</body>
</html>

总结

以上就是今天要讲的内容,本文仅仅简单介绍了css中的过渡及动画的使用。

欢迎大家灌水交流!

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 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
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值