Aspect Ratio Switcher
Motion and entrances @bhaskar Stars:0 Views:1
<div class="ar"><div class="pills"><button data-r="21/9">21:9</button><button data-r="16/9" class="on">16:9</button><button data-r="3/2">3:2</button><button data-r="4/3">4:3</button><button data-r="1/1">1:1</button><button data-r="4/5">4:5</button><button data-r="3/4">3:4</button><button data-r="2/3">2:3</button><button data-r="9/16">9:16</button></div><div class="stagebox"><div class="fr"><svg viewBox="0 0 400 260" preserveAspectRatio="xMidYMid slice"><defs><linearGradient id="sk" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#9cc3e6"/><stop offset="1" stop-color="#f3d9b8"/></linearGradient><linearGradient id="lk" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#2f8f83"/><stop offset="1" stop-color="#14524f"/></linearGradient></defs><rect width="400" height="260" fill="url(#sk)"/><path d="M0 170l60-50 40 30 70-70 60 60 50-40 120 90v70H0z" fill="#7d8c9c"/><path d="M0 190l80-40 60 40 90-60 70 50 100-20v100H0z" fill="#4f6a5a"/><path d="M230 120l90 70v30H200z" fill="#2c4a39"/><rect y="200" width="400" height="60" fill="url(#lk)"/><path d="M0 212h400" stroke="#ffffff30"/></svg></div></div></div>
<style>
.ar{width:380px;font-family:system-ui,-apple-system,sans-serif;display:grid;gap:18px;justify-items:center}.pills{display:flex;gap:2px;padding:4px;border-radius:999px;background:#202020}.pills button{border:0;background:none;color:#8a8a8a;font:500 11px/1 inherit;padding:8px 9px;border-radius:999px;cursor:pointer;transition:.25s}.pills button:hover{color:#ddd}.pills button.on{background:#111;color:#fff;font-weight:700}.stagebox{width:380px;height:210px;display:grid;place-items:center}.fr{width:373px;height:210px;border-radius:14px;overflow:hidden;transition:width .55s cubic-bezier(.3,.9,.3,1),height .55s cubic-bezier(.3,.9,.3,1);box-shadow:0 14px 34px rgba(0,0,0,.5)}.fr svg{display:block;width:100%;height:100%}
</style>
<script>
(function(){var fr=document.querySelector('.fr'),b=document.querySelectorAll('.pills button'),W=380,H=210;function fit(r){var p=r.split('/'),ar=p[0]/p[1],w=Math.min(W,H*ar),h=w/ar;fr.style.width=Math.round(w)+'px';fr.style.height=Math.round(h)+'px'}b.forEach(function(x){x.onclick=function(){b.forEach(function(y){y.classList.toggle('on',y===x)});fit(x.dataset.r)}});fit('16/9')})();
</script>