/    Sign up×
Community /Pin to ProfileBookmark

timer using images

hi

i need a timer that accepts a user’s input of minutes and seconds. and then on submit, a countdown to zero must be displayed using gif files representing the numbers 0 to 9.

i have called the gif files 0.gif, 1.gif, 2.gif etc.

please share any ideas

l.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@GollumOct 10.2003 — Have a look at this...
<i>
</i>&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
function txt2img(txt)
{
txt = txt.toString();
// assuming 0.gif, 1.gif, etc
var ret = "";
for ( var i = 0; i &lt; txt.length; i++ )
{
ret += '&lt;img src="' + txt.charAt(i) + '.gif"&gt;';
}
return ret;
}
var nSec;
function go()
{
var m = document.getElementById('min').value;
var s = document.getElementById('sec').value;

<i> </i>nSec = parseInt(m) * 60 + parseInt(s);

<i> </i>window.setTimeout("animate();", 1000);
}
function animate()
{
nSec--;
if ( nSec &gt; 0 )
{
document.getElementById('timer').innerHTML = txt2img(nSec);
window.setTimeout("animate();",1000);
}
else
{
document.getElementById('timer').innerHTML = "Blastoff!!!";
}
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;span id=timer&gt;
Time - &lt;input id=min type=text&gt;:&lt;input id=sec type=text&gt;&lt;br&gt;
&lt;button onclick="go();"&gt;Go&lt;/button&gt;
&lt;/span&gt;
&lt;/body&gt;
&lt;/html&gt;


... Should give you some pointers.
×

Success!

Help @lEZA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...