Skip to content

Instantly share code, notes, and snippets.

@dfelton
Created October 16, 2023 19:13
Show Gist options
  • Save dfelton/04f335d69fd7b18864a9b2bab448def7 to your computer and use it in GitHub Desktop.
Save dfelton/04f335d69fd7b18864a9b2bab448def7 to your computer and use it in GitHub Desktop.
Visual example for testing intervals in milliseconds
<?php
$ms = (int) ($_GET['ms'] ?? 1000);
if ($ms < 1) {
$ms = 1000;
}
?>
<html>
<head>
<title>Millisonds Example</title>
<style>
label {
color: #fff;
}
</style>
</head>
<body>
<form action="/ms-example.php" method="get">
<label for="ms">Milliseconds</label>
<input type="text" id="ms" name="ms" value="<?php echo (int) $ms ?>"/>
<input type="submit"/>
</form>
<script>
document.getElementById('ms').select()
let flag = false
function sleep()
{
setTimeout(backgroundUpdater, <?= (int) $ms ?>)
}
function backgroundUpdater()
{
flag = flag ? false : true;
document.body.style.backgroundColor = flag ? '#000' : '#808080'
sleep()
}
backgroundUpdater()
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment