Created
October 16, 2023 19:13
-
-
Save dfelton/04f335d69fd7b18864a9b2bab448def7 to your computer and use it in GitHub Desktop.
Visual example for testing intervals in milliseconds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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