Kopier den Code in eine HTML-Datei und schau dir das Beispiel an
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>JavaScript: Blinking Boxes - by Dominik Dopplinger</title>
<script type="text/javascript">
function init()
{
start_blink("my_box0", 20, false);
// ^ ^ ^
// | | |----------- Show error messages ( true | false )
// | |---------------- The time in milliseconds
// |------------------------ The ID of the HTML-Element, you want to blink
start_blink("my_box1", 40, false);
start_blink("my_box2", 80, false);
start_blink("my_box3", 160, false);
start_blink("my_box4", 320, false);
start_blink("my_box5", 640, false);
start_blink("my_box6", 1280, false);
}
function start_blink(id, time, errors)
{
blink_hide(id, time, errors);
}
function blink_hide(id, time, errors)
{
if(document.getElementById(id))
{
document.getElementById(id).style.visibility = "hidden";
window.setTimeout("blink_show('" + id + "', " + time + ", " + errors + ");", time);
}else if(errors)
window.alert("Could not find Element '" + id + "'");
}
function blink_show(id, time, errors)
{
if(document.getElementById(id))
{
document.getElementById(id).style.visibility = "visible";
window.setTimeout("blink_hide('" + id + "', " + time + ", " + errors + ");", time);
}else if(errors)
window.alert("Could not find Element '" + id + "'");
}
</script>
</head>
<body onload="init();">
<h1>JavaScript: Blinking Boxes - by Dominik Dopplinger</h1>
<p id="my_box0">Disco! ;D</p>
<p id="my_box1">Disco! ;D</p>
<p id="my_box2">Disco! ;D</p>
<p id="my_box3">Disco! ;D</p>
<p id="my_box4">Disco! ;D</p>
<p id="my_box5">Disco! ;D</p>
<p id="my_box6">Disco! ;D</p>
</body>
</html>
Alles anzeigen