HTMLify
plane
Views: 46 | Author: amar
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Sorry Gift</title> <style> * { box-sizing: border-box; } html,body { height: 100%; } body { margin: 0; height: 100vh; display: flex; align-items: center; justify-content: center; overflow: hidden; font-family: 'Poppins', sans-serif; background: #eaf4ff; /* flat sky color */ } .scene { perspective: 900px; } /* Gift (flat, clean) */ .gift { position: relative; width: 140px; height: 120px; cursor: pointer; animation: float 3s ease-in-out infinite; } .box { position: absolute; bottom: 0; width: 100%; height: 80px; background: #ff9acb; border-radius: 10px; box-shadow: 0 10px 20px rgba(0,0,0,0.12); } .lid { position: absolute; top: 0; width: 100%; height: 40px; background: #ff7fb8; border-radius: 12px 12px 6px 6px; transform-origin: bottom center; transition: transform 0.8s ease; } .ribbon-v { position: absolute; left: 50%; transform: translateX(-50%); width: 16px; height: 100%; background: #fff; border-radius: 4px; } .ribbon-h { position: absolute; top: 30px; width: 100%; height: 14px; background: #fff; border-radius: 4px; } @keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } } /* Sorry text */ .sorry { position: absolute; left: 50%; transform: translateX(-50%); top: -72px; font-size: 44px; font-weight: 700; color: #ff6aa8; opacity: 0; pointer-events: none; transition: opacity 0.6s ease, transform 0.6s ease; } /* Real butterfly using pseudo-elements for wings */ .butterfly { position: absolute; width: 20px; height: 18px; pointer-events: none; transform-origin: center bottom; animation: flyPath 3.6s cubic-bezier(.2,.8,.3,1) forwards; } .butterfly::before, .butterfly::after { content: ''; position: absolute; top: 0; width: 14px; height: 18px; background: radial-gradient(circle at 40% 30%, #ffd6e8 20%, #ff9acb 60%); border-radius: 60% 40% 60% 40% / 70% 60% 40% 30%; transform-origin: 2px 12px; animation: flap 0.36s ease-in-out infinite alternate; box-shadow: 0 2px 6px rgba(0,0,0,0.08); } .butterfly::after { left: 6px; transform-origin: 12px 12px; animation-delay: 0.06s; } @keyframes flap { from { transform: rotate(12deg) translateY(0); } to { transform: rotate(-28deg) translateY(-2px); } } /* Each butterfly will move up and sideways using CSS var --x and --y */ @keyframes flyPath { 0% { opacity: 0; transform: translateY(0) translateX(0) scale(0.9); } 5% { opacity: 1; } 50% { transform: translateY(-180px) translateX(var(--x, 0px)) scale(1.05); } 100% { transform: translateY(-380px) translateX(calc(var(--x, 0px) * 1.6)) scale(1.2); opacity: 0; } } /* small responsiveness */ @media (max-width:420px){ .gift{ width:120px; height:110px } .sorry{ font-size:28px; top:-54px } } </style> </head> <body> <div class="gift" id="gift"> <div class="lid" id="lid"></div> <div class="box"></div> <div class="ribbon-v"></div> <div class="ribbon-h"></div> <div class="sorry" id="sorryText">Sorry❤️</div> </div> <script> const gift = document.getElementById('gift'); const lid = document.getElementById('lid'); const sorryText = document.getElementById('sorryText'); let opened = false; function createButterfly(xOffset){ const b = document.createElement('div'); b.className = 'butterfly'; // start position near center of gift const startLeft = window.innerWidth/2 - 10 + (Math.random()*40 - 20); const startBottom = (window.innerHeight/2) - 30; b.style.left = startLeft + 'px'; b.style.bottom = startBottom + 'px'; const x = (Math.random()*200 - 100) + (xOffset||0); b.style.setProperty('--x', x + 'px'); b.style.animationDelay = (Math.random()*0.3) + 's'; document.body.appendChild(b); setTimeout(()=> b.remove(), 3800); } gift.addEventListener('click', () => { if (opened) return; opened = true; // open lid (tilt back) lid.style.transform = 'rotateX(-100deg) translateZ(6px)'; // show sorry text sorryText.style.opacity = '1'; sorryText.style.transform = 'translateX(-50%) translateY(-10px)'; // spawn butterflies for (let i=0;i<16;i++){ setTimeout(()=> createButterfly(i*6), i*90); } // small pop animation on gift gift.style.transform = 'translateY(-6px)'; setTimeout(()=> gift.style.transform = '', 700); }); // Optional: reopen prevention after some time (if you want to allow re-click, remove this) </script> </body> </html> |