CSS3绘制心跳爱心动画特效

html代码

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>CSS3绘制心跳爱心动画特效 - 站长素材</title>

<link rel="stylesheet" href="css/style.css">

</head>
<body>

<!--英文字体-->
<link href='https://fonts.googleapis.com/css?family=Cedarville+Cursive' rel='stylesheet' type='text/css'>

<div class="container">
  <div class="first-name">
    <span> love </span>
  </div>
  <div class="heart">
    <audio>
      <source src="mp3/heartbeat.mp3"></source>
    </audio>
    <span> doudou </span>
    <div class="right-heart"></div>
    <div class="left-heart"></div>
  </div>
  <div class="last-name">
    <span> you </span>
  </div>
</div>

<script  src="js/index.js"></script>

<div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
<p>适用浏览器:360、FireFox、Chrome、Opera、傲游、搜狗、世界之窗. 不支持Safari、IE8及以下浏览器。</p>
<p>来源:<a href="http://sc.chinaz.com/" target="_blank">站长素材</a></p>
</div>
</body>
</html>

css代码

body {
  background: #fcc;
  height: 100%;
}
body .container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  align-content: center;
}
body .container .first-name span {
  padding: 1rem;
  font-family: "Cedarville Cursive", cursive;
  font-size: 5rem;
  letter-spacing: 0.15rem;
  color: #bd2222;
}
body .container .last-name span {
  padding: 1rem;
  font-family: "Cedarville Cursive", cursive;
  font-size: 5rem;
  letter-spacing: 0.15rem;
  color: #bd2222;
}
body .container .heart {
  position: relative;
  height: 13rem;
  width: 13rem;
  background: #ff8a80;
  border-radius: 50%;
  animation: pulse 2s linear infinite;
}
body .container .heart span {
  position: absolute;
  color: #fcc;
  font-family: "Cedarville Cursive", cursive;
  font-size: 1.2rem;
  letter-spacing: 0.15rem;
  z-index: 2;
  top: 5.5rem;
  left: 4.2rem;
  opacity: 0;
}
body .container .heart span:hover {
  animation: apear 5s ease;
}
body .container .heart .right-heart {
  position: absolute;
  right: 3.2rem;
  top: 2.8rem;
  height: 55%;
  width: 30%;
  border-radius: 90% 100% 0 90%;
  background: #bd2222;
  transform: rotate(45deg);
}
body .container .heart .left-heart {
  position: absolute;
  left: 3.5rem;
  top: 2.9rem;
  height: 55%;
  width: 30%;
  border-radius: 100% 90% 90% 0;
  background: #bd2222;
  transform: rotate(-45deg);
}

@keyframes pulse {
  0% {
    transform: scale(0.9);
  }
  50% {
    transform: scale(1);
  }
  100% {
    transform: scale(0.9);
  }
}
@keyframes apear {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 0.5;
  }
  40% {
    opacity: 1;
  }
  60% {
    opacity: 0.5;
  }
  80% {
    opacity: 0.2;
  }
  100% {
    opacity: 0;
  }
}

JavaScript代码

const hover = document.querySelector(".heart");

const audio = document.querySelector("audio");

hover.addEventListener("mouseenter",function(){
  audio.play();
})

效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

千秋TʌT

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

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

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

打赏作者

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

抵扣说明:

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

余额充值