Skip to main content

timer

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://unpkg.com/xnew@5.0.x/dist/xnew.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>
</head>

<body class="relative m-0 p-0 w-full h-screen overflow-hidden">
<div id="main" class="relative w-full h-full"></div>
<script>
xnew('#main', (self) => {
xnew.nest('<div class="absolute w-128 h-64 inset-0 m-auto border rounded-lg overflow-hidden">');

xnew.interval(() => xnew(Box), 10);
});

function Box(self) {
const box = xnew.nest('<div class="absolute w-8 h-8 bg-orange-400">');
box.style.left = (Math.random() * 512 - 15) + 'px';
box.style.top = (Math.random() * 256 - 15) + 'px';

// fade in -> fade out -> finalize
xnew.transition((x) => box.style.opacity = x, 1000)
.next((x) => box.style.opacity = 1.0 - x, 1000)
.next((x) => self.finalize());

self.on('update', (count) => {
box.style.transform = `rotate(${count}deg)`;
});
}
</script>
</body>

</html>