Snippets: Stars Animation
@keyframes stars { 0% { opacity: 0; transform: translateY(40px) } 50% { opacity: 1; transform: translateY(10px) scale(1.4) } to { opacity: 1 } } html { font-size: 20px; background: #fff; } body { min-height: 100vh; display: flex; flex-flow: column nowrap; align-items: center; justify-content: center; } .star-box { position: relative; display: flex; flex-flow: column nowrap; align-items: center; justify-content: center; width: 70%; height: 180px; margin: 10px auto; border: 1px solid #d3e0da; border-radius: 4px; word-break: break-all; background: #F8FAF9; font-family: Nunito,sans-serif; } .star-box span { display: block; font-size: 30px; padding: 30px; } .star-box a { color: #fff !important; text-shadow: 0 1px 2px rgba(0,0,0,.4); border-radius: 6px; font-size: 20px; padding: 14px 18px; display: inline-block; background: linear-gradient(175deg,#d69721,#f08827 37%,#edad69); background: linear-gradient(175deg,#2198d6,#6996ed); font-weight: 700; text-decoration: none !important; transition: all .2s ease; } .star-box a:hover { opacity: 0.9; } .star-box .star-animation { -webkit-animation: stars 1s 1 forwards; animation: stars 1s 1 forwards; } .star-box .star { position: absolute; width: 60px; top: 0; opacity: 1 z-index: 999; } .star-box .star-1 { top: 25%; left: -28px; transform: rotate(-14deg) } .star-box .star-2 { top: -6px; left: 4.5%; width: 30px; transform: rotate(15deg); -webkit-animation-delay: .1s; animation-delay: .1s } .star-box .star-3 { top: auto; bottom: 58px; right: -15px; transform: rotate(15deg); -webkit-animation-delay: .2s; animation-delay: .2s } .star-box .star-4 { width: 40px; bottom: -14px; top: auto; right: 5px; transform: rotate(5deg); -webkit-animation-delay: .3s; animation-delay: .3s } .star-box .star-5 { width: 30px; bottom: 26px; top: auto; right: 10px; transform: rotate(-27deg); -webkit-animation-delay: .4s; animation-delay: .4s }
CSS Before Head
HTML Head
CSS After Head
JS Before HTML Body
<div class="star-box"> <span>Star Animation</span> <a href="https://caveops.com/" target="_blank">Check it out</a> <img class="star star-1" src="data:image/svg+xml;charset=UTF-8,%3csvg width='100%25' height='100%25' viewBox='0 0 77 68' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xml:space='preserve' xmlns:serif='http://www.serif.com/' style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg transform='matrix(3.04466,0,0,3.24785,-18.0325,-31.9862)'%3e%3cpath d='M18.581,10.334L22.516,16.638L30.595,17.96L24.948,23.179L26.006,30.3L18.581,27.221L11.156,30.3L12.214,23.179L6.567,17.96L14.646,16.638L18.581,10.334Z' style='fill:rgb(238,180,65);'/%3e%3c/g%3e%3c/svg%3e" /> <img class="star star-2" src="data:image/svg+xml;charset=UTF-8,%3csvg width='100%25' height='100%25' viewBox='0 0 77 68' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xml:space='preserve' xmlns:serif='http://www.serif.com/' style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg transform='matrix(3.04466,0,0,3.24785,-18.0325,-31.9862)'%3e%3cpath d='M18.581,10.334L22.516,16.638L30.595,17.96L24.948,23.179L26.006,30.3L18.581,27.221L11.156,30.3L12.214,23.179L6.567,17.96L14.646,16.638L18.581,10.334Z' style='fill:rgb(238,180,65);'/%3e%3c/g%3e%3c/svg%3e" /> <img class="star star-3" src="data:image/svg+xml;charset=UTF-8,%3csvg width='100%25' height='100%25' viewBox='0 0 77 68' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xml:space='preserve' xmlns:serif='http://www.serif.com/' style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg transform='matrix(3.04466,0,0,3.24785,-18.0325,-31.9862)'%3e%3cpath d='M18.581,10.334L22.516,16.638L30.595,17.96L24.948,23.179L26.006,30.3L18.581,27.221L11.156,30.3L12.214,23.179L6.567,17.96L14.646,16.638L18.581,10.334Z' style='fill:rgb(238,180,65);'/%3e%3c/g%3e%3c/svg%3e" /> <img class="star star-4" src="data:image/svg+xml;charset=UTF-8,%3csvg width='100%25' height='100%25' viewBox='0 0 77 68' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xml:space='preserve' xmlns:serif='http://www.serif.com/' style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg transform='matrix(3.04466,0,0,3.24785,-18.0325,-31.9862)'%3e%3cpath d='M18.581,10.334L22.516,16.638L30.595,17.96L24.948,23.179L26.006,30.3L18.581,27.221L11.156,30.3L12.214,23.179L6.567,17.96L14.646,16.638L18.581,10.334Z' style='fill:rgb(238,180,65);'/%3e%3c/g%3e%3c/svg%3e" /> <img class="star star-5" src="data:image/svg+xml;charset=UTF-8,%3csvg width='100%25' height='100%25' viewBox='0 0 77 68' version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' xml:space='preserve' xmlns:serif='http://www.serif.com/' style='fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;'%3e%3cg transform='matrix(3.04466,0,0,3.24785,-18.0325,-31.9862)'%3e%3cpath d='M18.581,10.334L22.516,16.638L30.595,17.96L24.948,23.179L26.006,30.3L18.581,27.221L11.156,30.3L12.214,23.179L6.567,17.96L14.646,16.638L18.581,10.334Z' style='fill:rgb(238,180,65);'/%3e%3c/g%3e%3c/svg%3e" /> </div>
HTML Body
HTML Foot
const observer_star = new IntersectionObserver(function(entries) { entries.forEach(entry => { const stars = entry.target.querySelectorAll('.star'); stars.forEach(star => { if (entry.isIntersecting) { star.classList.add('star-animation'); return; } star.classList.remove('star-animation'); }); }); }); observer_star.observe(document.querySelector('.star-box'));
JS After HTML Body
Full HTML Code