I'm missing a countdown timer that isn't based on a date but just by setting time.
How can I get this timer on a page?
Link
And if I need it between text do I have to add the text there?
Cheers.
How can I get this script between a text?
- Rebel Studio
-
- Posts: 73
- Joined: Tue Nov 04, 2008 10:55 pm
- Location: NL
- BaconFries
-
- Posts: 5948
- Joined: Thu Aug 16, 2007 7:32 pm
Re: How can I get this script between a text?
Here you are, I haven't tested so if it doesn't work please don't bite the hand that feeds you..☺
1: Place the following in a HTML Object
2: Insert the following between the <head></head> tags* in Page HTML
3: Insert the following in Page HTML Before </body>
Note you will need to make changes to the likes of the css to suit yourself.
1: Place the following in a HTML Object
Code: Select all
<div>Time left = <span id="timer"></span></div>
Code: Select all
<style>
body{
background-color:#2D3047;
}
div{
background-color:#419D78;
color:#EFD0CA;
font-size:20px;
text-align:center;
}
</style>
Code: Select all
<script>
document.getElementById('timer').innerHTML =
03 + ":" + 00;
startTimer();
function startTimer() {
var presentTime = document.getElementById('timer').innerHTML;
var timeArray = presentTime.split(/[:]+/);
var m = timeArray[0];
var s = checkSecond((timeArray[1] - 1));
if(s==59){m=m-1}
//if(m<0){alert('timer completed')}
document.getElementById('timer').innerHTML =
m + ":" + s;
setTimeout(startTimer, 1000);
}
function checkSecond(sec) {
if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10
if (sec < 0) {sec = "59"};
return sec;
}
</script>
- Rebel Studio
-
- Posts: 73
- Joined: Tue Nov 04, 2008 10:55 pm
- Location: NL
Re: How can I get this script between a text?
Cheers, will test it soon.BaconFries wrote: Mon Jul 02, 2018 2:48 am Here you are, I haven't tested so if it doesn't work please don't bite the hand that feeds you..☺
1: Place the following in a HTML Object2: Insert the following between the <head></head> tags* in Page HTMLCode: Select all
<div>Time left = <span id="timer"></span></div>
3: Insert the following in Page HTML Before </body>Code: Select all
<style> body{ background-color:#2D3047; } div{ background-color:#419D78; color:#EFD0CA; font-size:20px; text-align:center; } </style>
Note you will need to make changes to the likes of the css to suit yourself.Code: Select all
<script> document.getElementById('timer').innerHTML = 03 + ":" + 00; startTimer(); function startTimer() { var presentTime = document.getElementById('timer').innerHTML; var timeArray = presentTime.split(/[:]+/); var m = timeArray[0]; var s = checkSecond((timeArray[1] - 1)); if(s==59){m=m-1} //if(m<0){alert('timer completed')} document.getElementById('timer').innerHTML = m + ":" + s; setTimeout(startTimer, 1000); } function checkSecond(sec) { if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10 if (sec < 0) {sec = "59"}; return sec; } </script>
- BaconFries
-
- Posts: 5948
- Joined: Thu Aug 16, 2007 7:32 pm