Page 1 of 1

How can I get this script between a text?

Posted: Sun Jul 01, 2018 10:12 pm
by Rebel Studio
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.

Re: How can I get this script between a text?

Posted: Mon Jul 02, 2018 2:48 am
by BaconFries
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

Code: Select all

<div>Time left = <span id="timer"></span></div>
2: Insert the following between the <head></head> tags* in Page HTML

Code: Select all

<style>
body{
  background-color:#2D3047;
}
div{
  background-color:#419D78;
  color:#EFD0CA;
  font-size:20px;
  text-align:center;
}
</style>
3: Insert the following in Page HTML Before </body>

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>
Note you will need to make changes to the likes of the css to suit yourself.

Re: How can I get this script between a text?

Posted: Mon Jul 02, 2018 6:39 pm
by Rebel Studio
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 Object

Code: Select all

<div>Time left = <span id="timer"></span></div>
2: Insert the following between the <head></head> tags* in Page HTML

Code: Select all

<style>
body{
  background-color:#2D3047;
}
div{
  background-color:#419D78;
  color:#EFD0CA;
  font-size:20px;
  text-align:center;
}
</style>
3: Insert the following in Page HTML Before </body>

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>
Note you will need to make changes to the likes of the css to suit yourself.
Cheers, will test it soon.

Re: How can I get this script between a text?

Posted: Mon Jul 02, 2018 6:40 pm
by BaconFries
👌👍