spman
11-03-2012, 10:40 AM
Hi all - I am struggling to get some code working. What I want is the following :
1. There is a hidden div (basically just a block) on a page.
2. When the user presses an on screen <button> the div appears, turns blue, there is a 3 second delay and the div then dissapears again.
What I am guessing is happening with my code is that it is all working but there is no ouput to the document until the very end of the script by which time the div has been turned to display:none again?
Can anyone suggest the best way of doing this please?
Here is the example code :
<html>
<head>
<script type="text/javascript">
function pause(ms) {
ms += new Date().getTime();
while (new Date() < ms){}
}
function show() {
var b1=document.getElementById("bar1");
b1.style.backgroundColor="blue";
b1.style.display="block";
pause(3000);
b1.style.display="none";
}
</script>
</head>
<body>
<button name="test" onclick="show();">Press Me</button><br>
<div id="bar1" style="display:none; width:50px; height:40px;border:0px;"></div>
</body>
</html>
1. There is a hidden div (basically just a block) on a page.
2. When the user presses an on screen <button> the div appears, turns blue, there is a 3 second delay and the div then dissapears again.
What I am guessing is happening with my code is that it is all working but there is no ouput to the document until the very end of the script by which time the div has been turned to display:none again?
Can anyone suggest the best way of doing this please?
Here is the example code :
<html>
<head>
<script type="text/javascript">
function pause(ms) {
ms += new Date().getTime();
while (new Date() < ms){}
}
function show() {
var b1=document.getElementById("bar1");
b1.style.backgroundColor="blue";
b1.style.display="block";
pause(3000);
b1.style.display="none";
}
</script>
</head>
<body>
<button name="test" onclick="show();">Press Me</button><br>
<div id="bar1" style="display:none; width:50px; height:40px;border:0px;"></div>
</body>
</html>