Sunday 11 February 2018

Simple Countdown Based On Engagement Using Javascript

This Post assistance y'all how to produce countdown based on your given date. It automatically takes the countdown using engagement y'all are provided. It displays the years, months, days, hours, minutes together with seconds. It is really useful display the counter for the lawsuit launching together with whatever other novel production launching system.This countdown display amongst animation countdown cube.If y'all don't desire display about fields similar years thus y'all should withdraw the fields inward JavaScript. You tin strength out able to alter the fourth dimension zone inward the below javscript code i am using here Asia/Kolkata the default fourth dimension zone is UTC, It volition convert the utc to Asia/Kolkata. This concept is laid amongst given terminate time, It automatically calculated the years, months, days, hours, minutes, seconds together with display the results inward the cube div.



The below html code is used to display the amount countdown
<div id='counter' class='counter'></div>
And the countdowncube.css file used blueprint the counter boxes inward a perfect mode y'all tin strength out able to alter the styles together with colors according to your alternative to edit the countdowncube.css file. together with the countdowncube.js have the javascripts to display the counter y'all tin strength out edit together with customize the counters according to your choice.

I promise this uncomplicated concept is really useful to you. This lawsuit produce got the exhibit page delight cheque out the exhibit page together with download the amount code together with utilisation it to your website.

Countdown based on given date:

<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Simple Countdown based on Date using Jquery</title>
<meta name="description" content="Personal Website of Ali Cigari, jack of all trades...">
<meta name="viewport" content="initial-scale=1.0,width=device-width,user-scalable=0">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<link rel="stylesheet" href="countdowncube.css">
<style class="inlinestyle">
.counter {
margin: 10 auto;
text-align: center;
}
body
{
background-color: rebeccapurple;
}
</style>
</head>
<body>
<div id='counter' class='counter'></div>

<script src="countdowncube.js"></script>
<script>
var targetDate = novel Date();
targetDate.setMonth(targetDate.getMonth() + 18)
targetDate.setDate(1)
targetDate.setHours(11)
targetDate.setMinutes(0)
targetDate.setSeconds(0)
targetDate.setMilliseconds(0);

var targetDateStringUTC = targetDate.toISOString()
.replace(':00.000', '');
var targetDateString = targetDateStringUTC.replace('Z', '');

var targetLADate = moment.tz(targetDateStringUTC,
'Asia/Kolkata').format();
var tzLAOffset = targetLADate.substr(-6);
var targetDateStringOffset = targetDateString.replace('Z', '')
.replace(':00.000', '') +
tzLAOffset;

var tzOldFormatOffset = targetDateString.substr(-5);
var targetDateOldFormatString = targetDate.toLocaleDateString() +
' ' + tzOldFormatOffset;

var pastDate = novel Date();
pastDate.setMonth(targetDate.getMonth() - 18)
pastDate.setMinutes(0);
pastDate.setSeconds(0);
pastDate.setMilliseconds(0);
var targetDateStringPast = pastDate.toISOString()
.replace(':00.000', '');
var nearFutureDate = novel Date();
nearFutureDate.setSeconds(nearFutureDate.getSeconds() + 10);
nearFutureDate.setMilliseconds(0);
var nearFutureDateString = nearFutureDate.toISOString()
component subdivision reloadCounter(element_id,
new_target,
targetTimezone,
cubeSize,
background,
color,
onEnd,
triggerEnd) {

$(element_id).empty();

$(element_id).countdownCube( {
target: new_target,
targetTimezone: targetTimezone,
cubeSize: cubeSize,
background:  background,
color: color,
onEnd: onEnd,
triggerEnd: triggerEnd,
} );
};
</script>
<script>
$('#counter').countdownCube( {
target: targetDateStringUTC,
cubeSize: 150,
background:  '#ffff00',
color: 'blue',
} );

$('#counter-end-notrigger').countdownCube( {
target: targetDateStringPast,
targetTimezone: 'UTC',
cubeSize: 150,
background:  'lightcyan',
color: 'darkcyan',
/*
target is inward the by together with triggerEnd is false,
thus onEnd is non triggered when the page is loaded
*/
onEnd: function(e) {
$("#counter-end-notrigger")
.text('This was the end, but it was non triggered! ' +
'(counter master copy target: ' +
e.options.targetDateObject.toISOString() +
')');
}
} );
$('#counter-end-trigger').countdownCube( {
target: targetDateStringPast,
targetTimezone: 'UTC',
cubeSize: 150,
background:  'lightcyan',
color: 'cyan',
onEnd: function(e) {
$("#counter-end-trigger")
.text('This was the terminate together with it was triggered! ' +
'(counter master copy target: ' +
e.options.targetDateObject.toISOString() +
')');
},
triggerEnd: true,
} );

$('#counter').countdownCube({
target: novel Date( 'Feb 10, 2018 7:47:00' ),
cubeSize: 50
});
</script>
</body>
</html>


SHARE THIS

Author:

Just a regular website is not the website of incredible, but not also means the site is not responsible for all of what is in it, in this case the Admin, who manages this site fully responsible to what-what is published in it.

0 comments: