martin-schulz
Mitglied
Moin Moin
Was mache ich falsch. Ich möchte das bei meinem countdown zwischen einzahl und mehrzahl bei den tagen, stunden, minuten und sekunden unterschieden wird.
THX für eure Hilfe
Was mache ich falsch. Ich möchte das bei meinem countdown zwischen einzahl und mehrzahl bei den tagen, stunden, minuten und sekunden unterschieden wird.
Code:
// You may enter your date here
//first the year
var year = 2010;
//next the month
var month = 6;
//.. and the day
var day = 11;
//if you want to be more specific, you can add hours, minutse and seconds (the exact time):
//hours:
var hour = 12;
//minutes
var minute = 30;
//seconds
var second = 0;
//you can change the following images to your own ones, if you like to. There is always one plural and one singular (eg days and day)
var strDaysBig = ' <img src="http://www.tutorials.de/forum/images/text/daysleft.png" /> ';
var strDayBig = ' <img src="http://www.tutorials.de/forum/images/text/dayleft.png" /> ';
var strDays = ' <img src="http://www.tutorials.de/forum/images/text/days.png" /> ';
var strDay = ' <img src="http://www.tutorials.de/forum/images/text/day.png" /> ';
var strHours = ' <img src="http://www.tutorials.de/forum/images/text/hours.png" /> ';
var strHour = ' <img src="http://www.tutorials.de/forum/images/text/hour.png" /> ';
var strMinutes = ' <img src="http://www.tutorials.de/forum/images/text/minutes.png" /> ';
var strMinute = ' <img src="http://www.tutorials.de/forum/images/text/minute.png" /> ';
var strSeconds = ' <img src="http://www.tutorials.de/forum/images/text/seconds.png" /> ';
var strSecond = ' <img src="http://www.tutorials.de/forum/images/text/second.png" /> ';
//this is the message users will see when the countdown is finished. of course you can replace it with your own one.
var strTimesUp = ' Time is up but we still are not available. We are sorry. Please stay tuned!';
//configuration
var showIfEZero = true ; // change to true if you want to have the full date displayed. Default is false
// example if true: 0 days 0 hours 0 minutes 20 seconds
// example if false: 20 seconds
// NOTE: this only affects the second countdown. The big days counter will always be shown!
//DO NOT CHANGE ANYTHING FROM NOW ON, IF YOU DON'T KNOW WHAT YOU ARE DOING!
var countTo = new Date(year, month-1,day,hour,minute,second);
function countdown() {
fromNow=new Date();
if(fromNow<countTo) {
var daysLeft=0, hoursLeft=0, minutesLeft=0, secondsLeft=0;
while(fromNow.getTime() + (24 * 60 * 60 * 1000) < countTo) {
daysLeft++;
fromNow.setTime(fromNow.getTime() + (24 * 60 * 60 * 1000));
}
daysLeftBig = numberToImage(daysLeft, 'big');
daysLeft = numberToImage(daysLeft, 'small');
hoursLeft = Math.floor((countTo - fromNow) / (60 * 60 * 1000));
fromNow.setTime(fromNow.getTime() + hoursLeft * 60 * 60 * 1000);
hoursLeft = numberToImage(hoursLeft, 'small');
minutesLeft = Math.floor((countTo - fromNow) / (60 * 1000));
fromNow.setTime(fromNow.getTime() + minutesLeft * 60 * 1000);
minutesLeft = numberToImage(minutesLeft, 'small');
secondsLeft = Math.floor((countTo - fromNow) / 1000);
secondsLeft = numberToImage(secondsLeft, 'small');
var showDayBig = true;
var showDay = true;
var showHour = true;
var showMinute = true;
var showSecond = true;
if(!showIfEZero) {
showDay = (daysLeft == 0) ? false : true;
showHour = (hoursLeft == 0) ? false : true;
showMinute = (minutesLeft == 0) ? false : true;
showSecond = (secondsLeft == 0) ? false : true;
}
(daysLeftBig != 1) ? daysLeftBig = daysLeftBig + strDaysBig : daysLeftBig = daysLeftBig + strDayBig;
(daysLeft != 1) ? daysLeft = daysLeft + strDays : daysLeft = daysLeft + strDay;
(hoursLeft != 1) ? hoursLeft = hoursLeft + strHours : hoursLeft = hoursLeft + strHour;
(minutesLeft != 1) ? minutesLeft = minutesLeft + strMinutes : minutesLeft = minutesLeft + strMinute;
(secondsLeft != 1) ? secondsLeft = secondsLeft + strSeconds : secondsLeft = secondsLeft + strSecond;
//big countdown
var showStrBig = '';
var showStrBig = (showDayBig) ? showStrBig + daysLeftBig : showStrBig;
//small countdown
var showStr = '';
var showStr = (showDay) ? showStr + daysLeft : showStr;
var showStr = (showHour) ? showStr + hoursLeft : showStr;
var showStr = (showMinute) ? showStr + minutesLeft : showStr;
var showStr = (showSecond) ? showStr + secondsLeft : showStr;
//display string in element with ID "countdown".
document.getElementById('countdown').innerHTML = showStr;
document.getElementById('countdownBig').innerHTML = showStrBig;
setTimeout('countdown()',200);
}
// set Time is Up message
else document.getElementById('countdown').innerHTML = strTimesUp;
}
//this function changes the numbers into images
function numberToImage (number, type) {
number = number.toString();
string = '';
for(i=0;i<number.length;i++) {
display = number.split('');
if(type == 'big') {
string = string + '<img src="http://www.tutorials.de/forum/images/numbers/'+type+'/'+display[i]+'.png" style="width: 81px; height: 107px;" />';
}else {
string = string + '<img src="http://www.tutorials.de/forum/images/numbers/'+type+'/'+display[i]+'.png" style="width: 13px; height: 27px;" />';
}
}
return string;
}
THX für eure Hilfe