I am having a little trouble figuring out how to make this work properly, I am trying to put a small countdown clock in the left column and one in the right column, which will show a countdown to two separate dates. I was able to create a single countdown clock using the below code and was hoping to be able to be able to tweak the code enough to allow it to run on a second CEWP with a different date. Is it possible to run two Javascript files on the page without them interferring with eachother? Thank you anyone that can lend a quick hand.
<style type="text/css">
.container{
text-align: center;
background: #f63536;
font-family: sans-serif;
font-weight: 100;
height:115px;
width:215px;
}
h3{
color: #FFFFFF;
font-weight: 100;
font-size: 16px;
margin: 0px 0px 5px;
padding-top:3px;
}
#clockdiv{
font-family: sans-serif;
color: #fff;
display: inline-block;
font-weight: 100;
text-align: center;
font-size: 20px;
}
#clockdiv > div{
padding: 5px;
border-radius: 3px;
background: #ff5b5b;
display: inline-block;
}
#clockdiv div > span{
padding: 5px;
border-radius: 3px;
background: #ab0202;
display: inline-block;
}
.smalltext{
padding-top: 5px;
font-size: 13px;
}
</style>
<div class="container">
<h3>Countdown Clock Left</h3>
<div id="clockdiv">
<div>
<span class="days"></span>
<div class="smalltext">Days</div>
</div>
<div>
<span class="hours"></span>
<div class="smalltext">Hrs.</div>
</div>
<div>
<span class="minutes"></span>
<div class="smalltext">Min.</div>
</div>
<div>
<span class="seconds"></span>
<div class="smalltext">Sec.</div>
</div>
</div></div>
<script>
function getTimeRemaining(endtime){
var t = Date.parse(endtime) - Date.parse(new Date());
var seconds = Math.floor( (t/1000) % 60 );
var minutes = Math.floor( (t/1000/60) % 60 );
var hours = Math.floor( (t/(1000*60*60)) % 24 );
var days = Math.floor( t/(1000*60*60*24) );
return {
'total': t,
'days': days,
'hours': hours,
'minutes': minutes,
'seconds': seconds
};
}
function initializeClock(id, endtime){
var clock = document.getElementById(id);
var daysSpan = clock.querySelector('.days');
var hoursSpan = clock.querySelector('.hours');
var minutesSpan = clock.querySelector('.minutes');
var secondsSpan = clock.querySelector('.seconds');
function updateClock(){
var t = getTimeRemaining(endtime);
daysSpan.innerHTML = t.days;
hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
if(t.total<=0){
clearInterval(timeinterval);
}
}
updateClock();
var timeinterval = setInterval(updateClock,1000);
}
var deadline = 'October 31 2015 00:00:50';
initializeClock('clockdiv', deadline);
</script>