2024-05-04 css实现鼠标移动至盒子,盒子在约定时间内进行放大缩小
放大缩小css
@keyframes scaleAnimation { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }
完整代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>css实现鼠标移动至图片,图片在约定时间内进行放大缩小</title>
<style>
.box {
width: 100px;
height: 100px;
cursor: pointer;
transition: all 0.5s;
margin: 100px auto 0;
background-color: #1890ff;
}
.box:hover {
animation: scaleAnimation 1s 1;
}
@keyframes scaleAnimation {
0% {
transform: scale(1);
}
50% {
transform: scale(1.2);
}
100% {
transform: scale(1);
}
}
</style>
</head>
<body>
<div class="box"></div>
</body>
</html>
主要是使用了css3的动画属性,如果不需要自动放大缩小,而是hover放大,离开就缩小,那么就不用animation,直接一个 transform: scale(2) 即可

浙公网安备 33010602011771号