HTML5表白特效源代碼
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>表白特效</title> <style> body{ background-color: #fafafa; } .container{ width: 100%; height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; } .heart{ width: 50px; height: 50px; background-color: #ea2839; transform: rotate(45deg); position: relative; animation: fly 1.5s ease forwards; } .heart::before{ content: ""; width: 50px; height: 50px; background-color: #ea2839; position: absolute; top: -25px; left: 0; border-radius: 25px 25px 0 0; } .heart::after{ content: ""; width: 50px; height: 50px; background-color: #ea2839; position: absolute; top: 0; left: -25px; border-radius: 25px 25px 0 0; } @keyframes fly{ 0%{ transform: rotate(45deg) scale(1); } 50%{ transform: translateY(-300px) rotate(45deg) scale(0.8); } 80%{ transform: translateY(-500px) rotate(45deg) scale(0.5); } 100%{ transform: translateY(-700px) rotate(45deg) scale(0.3); opacity: 0; } } </style> </head> <body> <div class="container"> <div class="heart"></div> </div> </body> </html>
以上是一個簡單的表白特效,頁面中一個紅色的心形圖案從底部飛向上方,表示情人間的青澀和浪漫。這個特效主要利用了CSS動畫和transform屬性進行制作,代碼簡單易懂,適合初學者進行學習和實現。