html 爱心动态代码
时间: 2023-10-11 10:11:22 浏览: 119
HTML中可以使用CSS和JavaScript来创建爱心动态效果。以下是一个示例代码:
```html
<!DOCTYPE html>
<html>
<head>
<style>
@keyframes heartBeat {
0% {
transform: scale(1);
}
10% {
transform: scale(0.9);
}
20% {
transform: scale(1);
}
30% {
transform: scale(0.9);
}
40% {
transform: scale(1);
}
100% {
transform: scale(1);
}
}
.container {
position: relative;
width: 200px;
height: 200px;
}
.heart {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) rotate(-45deg);
width: 100px;
height: 100px;
background-color: red;
}
.heart:before,
.heart:after {
content: "";
position: absolute;
width: 100px;
height: 100px;
background-color: red;
}
.heart:before {
border-radius: 100px 100px 0 0;
top: -50px;
left: 0px;
}
.heart:after {
border-radius: 100px 100px 100px 0;
top: 0px;
left: 50px;
}
.heart:hover {
animation: heartBeat 1s infinite;
}
</style>
</head>
<body>
<div class="container">
<div class="heart"></div>
</div>
</body>
</html>
```
这段代码使用了CSS的`@keyframes`动画和`transform`属性来实现心形图案的动态效果。当鼠标悬停在心形图案上时,会触发动画效果。
阅读全文