Einfacher-Javascript-Countdown.php


Quell Code


<script src="/js/index.php?js=3.2.1-jquery.min.js"></script>
<h1>Kleiner einfacher Javascript Countdown</h1>
<table>
<tr><th> Jahr</th><th> Monat </th><th> Tag </th><th> Stunde </th><th> Minuten </th><th> Sekunden </th></tr>
    <tbody>
        <tr>
             <td><input type="number" id="jahr" min="2020" max="3000" value="2020"></td>
             <td><input type="number" id="monat" min="1" max="12" value="12"></td>
             <td><input type="number" id="tag" min="1" max="31" value="31"></td>
             <td><input type="number" id="stunde" min="0" max="1" value="23"></td>
             <td><input type="number" id="minute" min="0" max="59" value="59"></td>
             <td><input type="number" id="sekunde" min="0" max="59" value="59"></td>
        </tr>
        <tr id="countdown_div">
          	 <td colspan="6">Hier steht der Countdown...</td>
        </tr>
    </tbody>
</table>
<script>
var timer;
function countdown() {
    window.setTimeout("countdown()", 1000);
	var bis = new Date($('#jahr').val(), ($('#monat').val() - 1), $('#tag').val(), $('#stunde').val(), $('#minute').val(), $('#sekunde').val());
	var jetzt = new Date(); 
    var rest = Math.floor((bis-jetzt.getTime())/1000);
	var wochen = 0;
	var tage = 0;
	var stunden = 0;
	var minuten = 0;
	if (rest >= 604800) {
		wochen = Math.floor(rest/604800);
		rest -= wochen*604800;
	}
	if (rest >= 86400) {
		tage = Math.floor(rest/86400);
		rest -= tage*86400;
	}
	if (rest >= 3600) {
		stunden = Math.floor(rest/3600);
		rest -= stunden*3600;
	}
	if (rest >= 60) {
		minuten = Math.floor(rest/60);
		rest -= minuten*60;
	}
	$('#countdown_div').html('<td> Ende in </td><td>'+wochen+' Wochen, </td><td>'+tage+' Tage,</td><td> '+stunden+' Stunden,</td><td> '+minuten+' Minuten</td><td> und '+rest+' Sekunden</td>');
}
$('input').change(function(){
    clearInterval(timer);
    lauf();
});
function lauf(){
   timer=setInterval(function(){
        countdown() 
   },1000)
}
lauf();

</script>

Add Comment

* Required information
1000
Drag & drop images (max 1)
Powered by Commentics

Comments

No comments yet. Be the first!

Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0