How can I get this script between a text?

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
User avatar
Rebel Studio
 
 
Posts: 73
Joined: Tue Nov 04, 2008 10:55 pm
Location: NL

How can I get this script between a text?

Post 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.
User avatar
BaconFries
 
 
Posts: 5328
Joined: Thu Aug 16, 2007 7:32 pm

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

Post 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.
User avatar
Rebel Studio
 
 
Posts: 73
Joined: Tue Nov 04, 2008 10:55 pm
Location: NL

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

Post 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.
User avatar
BaconFries
 
 
Posts: 5328
Joined: Thu Aug 16, 2007 7:32 pm

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

Post by BaconFries »

👌👍
Post Reply