[HTML/CSS]动画效果以及自定义动画效果

一,实现div或者文字的当鼠标浮于其上时的动画效果:

1,transition加在div中,实现动画效果的过渡效果,transition: all 3s;其中all表示所有样式都参与过渡,3s表示实现效果的时间;linear为使动画匀速进行;

2,transform放在hover中实现动画效果,translate表示位置的移动;scale表示缩放,其中的值为原大小的几倍;rotate表示旋转,其中旋转的度数单位为deg。

<html>
	<head>
		<meta charset="utf-8">
		<style>
			div{
				width: 300px;
				height: 300px;
				background: skyblue;
				/* 动画过渡效果 */
				transition: all 3s linear;
			}
			div:hover{
				background: rgb(0, 47, 167);
				/* transform 2d动画;translate 位置移动 */
				/* scale 缩放 */
				/* rotate 旋转;deg表示度数 */
				/* transform: rotate(60deg); */
				transform: translate(50px) scale(0.5) rotate(360deg);
			}
		</style>
	</head>
	<body>
		<div>
			
		</div>
	</body>
</html>

二,实现自定义动画效果:

1,自定义动画效果为设置一个keyframes关键字用来定义此动画效果,

        @keyframes abc {
                20%{
                }
                40%{
                }
                60%{
                }
                80%{
                }
                100%{
                }
            }

        其中abc为此动画的名字,百分数为该动画效果每时间段内的样式,

2,调用定义好的动画效果:animation: abc 1s infinite linear;

        abc为动画名,1s为动画时间,infinite使动画循环进行,linear为使动画匀速进行。

        例子代码:

<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			body{
				background-color: black;
			}
			div{
				width: 800px;
				height: 100px;
				line-height: 100px;
				background: skyblue;
				margin: 50px auto;
				color: white;
				font-size: 60px;
				font-weight: bold;
				text-align: center;
				animation: abc 1s infinite linear;
			}
			@keyframes abc {
				20%{
					background-color: blue;
					color: white;
				}
				40%{
					background-color: gold;
					color: black;
				}
				60%{
					background-color: red;
					color: green;
				}
				80%{
					background-color: green;
					color: purple;
				}
				100%{
					background-color: purple;
					color: yellow;
				}
			}
		</style>
	</head>
	<body>
		<div>
			到沈阳了,指定没你好果汁吃
		</div>
	</body>
</html>

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值