JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="/style.css">
</head>
<body>
<div>
<button onclick="show('popup1')">Show with @starting-style</button>
<button class="irrelevant popup popup1" onclick="hide('popup1')">Close 1</button>
</div>
<div>
<button onclick="show('popup2')">Show without @starting-style</button>
<button class="irrelevant popup popup2" onclick="hide('popup2')">Close 2</button>
</div>
</body>
</html>
CSS
* {
padding: 0;
margin: 0;
}
body {
display: grid;
grid-template-columns: 50vw 50vw;
gap: 1rem;
padding: 1rem;
}
body > div {
display: flex;
flex-direction: column;
border: 3px solid black;
height: 100vh;
}
.irrelevant {
height: 200px;
background: darkgray;
}
.popup {
display: none;
transition:
display 0.7s,
translate 0.7s ease-out;
translate: 0 50vh;
}
.popup.open {
display: block;
translate: 0 0;
}
.popup1.open {
@starting-style {
translate: 0 50vh;
}
}
JavaScript
function getElement(popupName) {
return document.querySelector("." + popupName)
}
function hide(popupName) {
getElement(popupName).classList.remove("open")
}
function show(popupName) {
getElement(popupName).classList.add("open")
}