-
Notifications
You must be signed in to change notification settings - Fork 54
/
index.html
455 lines (413 loc) · 18.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>simplyCountdown.js | A Tiny and dead simple Javascript Countdown Library</title>
<meta name="author" content="Vincent Loy"/>
<meta name="keywords" content="Vincent Loy, Javascript, Javascript Library, Javascript Countdown, jQuery Countdown, JS, JS Countdown, Countdown, Countup"/>
<meta name="description" content="simplyCountdown.js is an easy to use Javascript Countdown Library. You can easly customize it with your own CSS and versatile parameters."/>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&family=Wix+Madefor+Text:ital,wght@0,400..800;1,400..800&display=swap" rel="stylesheet">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css"/>
<link rel="stylesheet" href="css/simplyCountdown.theme.losange.css"/>
<link rel="stylesheet" href="css/simplyCountdown.theme.default.css"/>
<link rel="stylesheet" href="css/demo-only/prism.css"/>
<link rel="stylesheet" href="css/demo.css"/>
</head>
<body>
<header class="row center-xs">
<div class="header-content">
<h1>simplyCountdown.js</h1>
<h2>A Tiny Javascript Countdown Library</h2>
<p class="sc-inline-header">
You're just
<span class="sc-inline-header__cd bold"></span>
away from discovering the perfect Countdown Library for your next project!
</p>
<div class="repo-buttons">
<a href="https://github.com/VincentLoy/simplyCountdown.js" class="button">
<i class="fa fa-github"></i> <span>View on GitHub</span>
</a>
<a href="https://github.com/VincentLoy/simplyCountdown.js/archive/master.zip"
class="button">
<i class="fa fa-download"></i> <span>Download Sources</span>
</a>
</div>
</div>
</header>
<main class="container">
<section class="intro">
<h2>Why another countdown ?</h2>
<p>
I created this little library on a day when I had some extra time,
inspired by my regular need for JavaScript countdown solutions on websites.
This library is designed to meet my exact needs for simplicity and flexibility,
making it perfect for use cases like 'under construction' pages or upcoming event countdowns.
</p>
<p>
This JavaScript countdown library is lightweight and easy to use—ideal for developers who want a straightforward,
customizable countdown without the unnecessary complexity of many other libraries. Whether it's for landing pages,
promotions, or personal projects, this solution can help you add engaging countdown timers effortlessly.
</p>
<p>
simplyCountdown.js has been adopted by a variety of projects where developers needed a simple, reliable countdown solution.
Its lightweight nature and ease of customization make it an appealing choice for straightforward use cases like 'under construction' pages or event countdowns
</section>
<section class="getting-started">
<h2>Getting Started</h2>
<h3>install via yarn, npm, <a
href="https://github.com/VincentLoy/simplyCountdown.js/archive/master.zip">direct
download</a></h3>
<pre>
<code class="ff-code">
$ npm install simplycountdown.js
// or
$ yarn add simplycountdown.js
</code>
</pre>
<h3>Insert simplyCountdown to your HTML</h3>
<pre>
<code class="language-html">
<link rel="stylesheet" href="css/simplyCountdown.theme.default.css"/>
<script src="dist/simplyCountdown.min.js"></script>
</code>
</pre>
<pre>
<code class="language-javascript">
// This is an example with default parameters
// You'll always have to call simplyCountdown using ID's, no classes.
simplyCountdown('[CSS-SELECTOR]', {
year: 2015, // Target year (required)
month: 6, // Target month [1-12] (required)
day: 28, // Target day [1-31] (required)
hours: 0, // Target hour [0-23], default: 0
minutes: 0, // Target minute [0-59], default: 0
seconds: 0, // Target second [0-59], default: 0
words: { // Custom labels, with lambda for plurals
days: { root: 'day', lambda: (root, n) => n > 1 ? root + 's' : root },
hours: { root: 'hour', lambda: (root, n) => n > 1 ? root + 's' : root },
minutes: { root: 'minute', lambda: (root, n) => n > 1 ? root + 's' : root },
seconds: { root: 'second', lambda: (root, n) => n > 1 ? root + 's' : root }
},
plural: true, // Use plurals for labels
inline: false, // Inline format: e.g., "24 days, 4 hours, 2 minutes"
inlineSeparator: ', ', // Separator for inline format, default: ", "
inlineClass: 'simply-countdown-inline', // CSS class for inline countdown
enableUtc: false, // Use UTC time if true
onEnd: function () {}, // Callback when countdown ends
refresh: 1000, // Refresh interval in ms, default: 1000
sectionClass: 'simply-section', // CSS class for each countdown section
amountClass: 'simply-amount', // CSS class for numeric values
wordClass: 'simply-word', // CSS class for unit labels
zeroPad: false, // Pad numbers with leading zero
removeZeroUnits: false, // Remove units with zero value
countUp: false // Count up after reaching zero
});
// Also, you can init with already existing Javascript Object.
let myElement = document.querySelector('.my-countdown');
simplyCountdown(myElement, { /* options */ });
let multipleElements = document.querySelectorAll('.my-countdown');
simplyCountdown(multipleElements, { /* options */ });
</code>
</pre>
<h3>You can use it with jQuery too (not required)</h3>
<pre>
<code class="language-javascript">
// jQuery Example
$('[SELECTOR]').simplyCountdown({
year: 2015, // required
month: 6, // required
day: 28, // required
...
});
</code>
</pre>
<h3>Parameters</h3>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td><code class="ff-code">year</code></td>
<td>Number (required)</td>
<td>The target year for the countdown.</td>
<td>-</td>
</tr>
<tr>
<td><code class="ff-code">month</code></td>
<td>Number (required)</td>
<td>The target month [1-12] for the countdown.</td>
<td>-</td>
</tr>
<tr>
<td><code class="ff-code">day</code></td>
<td>Number (required)</td>
<td>The target day [1-31] for the countdown.</td>
<td>-</td>
</tr>
<tr>
<td><code class="ff-code">hours</code></td>
<td>Number</td>
<td>The target hour [0-23].</td>
<td>0</td>
</tr>
<tr>
<td><code class="ff-code">minutes</code></td>
<td>Number</td>
<td>The target minute [0-59].</td>
<td>0</td>
</tr>
<tr>
<td><code class="ff-code">seconds</code></td>
<td>Number</td>
<td>The target second [0-59].</td>
<td>0</td>
</tr>
<tr>
<td><code class="ff-code">words</code></td>
<td>Object</td>
<td>Custom labels for the units (days, hours, minutes, seconds) with optional lambda function for correct pluralization.</td>
<td>
<code class="ff-code">{ days: { root: 'day', lambda: (root, n) => n > 1 ? root + 's' : root }, ... }</code>
</td>
</tr>
<tr>
<td><code class="ff-code">plural</code></td>
<td>Boolean</td>
<td>Whether to use plural forms for the unit labels.</td>
<td><code class="ff-code">true</code></td>
</tr>
<tr>
<td><code class="ff-code">inline</code></td>
<td>Boolean</td>
<td>Set to <code class="ff-code">true</code> for a simple inline countdown (e.g., "24 days, 4 hours, 2 minutes").</td>
<td><code class="ff-code">false</code></td>
</tr>
<tr>
<td><code class="ff-code">inlineSeparator</code></td>
<td>String</td>
<td>Separator used in the inline countdown format.</td>
<td><code class="ff-code">", "</code></td>
</tr>
<tr>
<td><code class="ff-code">inlineClass</code></td>
<td>String</td>
<td>CSS class applied to the inline countdown container.</td>
<td><code class="ff-code">"simply-countdown-inline"</code></td>
</tr>
<tr>
<td><code class="ff-code">enableUtc</code></td>
<td>Boolean</td>
<td>Set to <code class="ff-code">true</code> to use UTC time for the countdown calculations.</td>
<td><code class="ff-code">false</code></td>
</tr>
<tr>
<td><code class="ff-code">onEnd</code></td>
<td>Function</td>
<td>Callback function executed when the countdown ends.</td>
<td><code class="ff-code">() => {}</code></td>
</tr>
<tr>
<td><code class="ff-code">refresh</code></td>
<td>Number</td>
<td>The countdown refresh interval in milliseconds.</td>
<td><code class="ff-code">1000</code></td>
</tr>
<tr>
<td><code class="ff-code">sectionClass</code></td>
<td>String</td>
<td>CSS class applied to each countdown section (days, hours, minutes, seconds).</td>
<td><code class="ff-code">"simply-section"</code></td>
</tr>
<tr>
<td><code class="ff-code">amountClass</code></td>
<td>String</td>
<td>CSS class applied to the numeric value of each countdown section.</td>
<td><code class="ff-code">"simply-amount"</code></td>
</tr>
<tr>
<td><code class="ff-code">wordClass</code></td>
<td>String</td>
<td>CSS class applied to the unit label of each countdown section.</td>
<td><code class="ff-code">"simply-word"</code></td>
</tr>
<tr>
<td><code class="ff-code">zeroPad</code></td>
<td>Boolean</td>
<td>Whether to pad the numeric values with leading zeros (e.g., "05").</td>
<td><code class="ff-code">false</code></td>
</tr>
<tr>
<td><code class="ff-code">removeZeroUnits</code></td>
<td>Boolean</td>
<td>Remove units with zero value (e.g., remove "0 days" if days are zero).</td>
<td><code class="ff-code">false</code></td>
</tr>
<tr>
<td><code class="ff-code">countUp</code></td>
<td>Boolean</td>
<td>Count up after reaching zero if set to <code class="ff-code">true</code>.</td>
<td><code class="ff-code">false</code></td>
</tr>
</tbody>
</table>
</div>
</section>
<section class="custom">
<h2>Easy to customize</h2>
<p>
You can easly customize the countdown using the css theme starter file or create your
own like so :
</p>
<div class="note">
<p>
<i class="fa fa-info"></i> The following theme template works with default
class in parameters
</p>
</div>
<pre>
<code class="language-css">
/**
* Project : simply-countdown
* File : simplyCountdown.theme.custom
* Author : Your Name <your-mail[at]example.com>
*/
.simply-countdown {
/* The countdown */
}
.simply-countdown > .simply-section {
/* coutndown blocks */
}
.simply-countdown > .simply-section > div {
/* countdown block inner div */
}
.simply-countdown > .simply-section .simply-amount,
.simply-countdown > .simply-section .simply-word {
/* amounts and words */
}
.simply-countdown > .simply-section .simply-amount {
/* amounts */
}
.simply-countdown > .simply-section .simply-word {
/* words */
}
</code>
</pre>
</section>
<h2>Examples</h2>
<h3>Default</h3>
<p>Displayed whithout jQuery - UTC enabled</p>
<div class="simply-countdown simply-countdown-one"></div>
<h3>Custom</h3>
<p>Displayed with jQuery - UTC disabled</p>
<div class="simply-countdown-losange" id="simply-countdown-losange"></div>
<h3>Remove Zero Units</h3>
<p>Displayed with removeZeroUnits enabled</p>
<div class="simply-countdown simply-countdown-two"></div>
<h3>Inline</h3>
<p>Display a simple inline countdown</p>
<div class="simply-countdown-inline"></div>
<h3>countup</h3>
<p>countup Enabled option</p>
<div class="simply-countdown simply-countdown-countup" id="simply-countdown-countup"></div>
</section>
</main>
<footer>
<p>
Made with ❤ by
<a href="https://github.com/VincentLoy"
target="_blank">
Vincent Loy
</a>
</p>
</footer>
<div class="alert show-after-header-cd">
You like simplyCountdown ? <a href="https://github.com/VincentLoy/simplyCountdown.js" target="_blank">Give it a star on Github !</a>
</div>
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/0.0.1/prism.min.js"></script>
<script src="dev/simplyCountdown.js"></script>
<script>
/**
* WARNING: I set this coundtown to be running until the end of times.
* So when you'll init the plugin, follow how it's done in plugin documentation.
* e.g : instead of "month: d.getMonth() + 1" put "month: 10" for October.
*/
let d = new Date(),
countUpDate = new Date();
d.setMonth(d.getMonth() + 1);
// default example
simplyCountdown('.simply-countdown-one', {
year: d.getFullYear(),
month: d.getMonth() + 1,
day: d.getDate(),
enableUtc: true
});
//jQuery example
$('#simply-countdown-losange').simplyCountdown({
year: d.getFullYear(),
month: d.getMonth() + 1,
day: d.getDate(),
enableUtc: false
});
// example with removeZeroUnits
simplyCountdown('.simply-countdown-two', {
year: d.getFullYear(),
month: d.getMonth() + 1,
day: d.getDate() - 30,
removeZeroUnits: true
});
// inline example
simplyCountdown('.simply-countdown-inline', {
year: d.getFullYear(),
month: d.getMonth() + 1,
day: d.getDate(),
inline: true
});
// Header inline Countdown
let dateInTwoMinutes = new Date();
//dateInTwoMinutes.setMinutes(dateInTwoMinutes.getMinutes() + 1);
dateInTwoMinutes.setSeconds(dateInTwoMinutes.getSeconds() + 30);
simplyCountdown('.sc-inline-header__cd', {
year: dateInTwoMinutes.getFullYear(),
month: dateInTwoMinutes.getMonth() + 1,
day: dateInTwoMinutes.getDate(),
hours: dateInTwoMinutes.getHours(),
minutes: dateInTwoMinutes.getMinutes(),
seconds: dateInTwoMinutes.getSeconds(),
removeZeroUnits: true,
inline: true,
inlineSeparator: ' - ',
onEnd: () => {
let afterHeaderCdAlert = document.querySelector('.show-after-header-cd');
afterHeaderCdAlert.classList.add('active');
document.querySelector('.sc-inline-header').classList.add('hide');
window.setInterval(() => {
afterHeaderCdAlert.classList.remove('active');
}, 20000);
}
});
// direct element injection & Count Up Example
var countUp = document.querySelector('.simply-countdown-countup');
simplyCountdown(countUp, {
year: countUpDate.getFullYear(),
month: countUpDate.getMonth() + 1,
day: countUpDate.getDate(),
hours: countUpDate.getHours(),
minutes: countUpDate.getMinutes(),
seconds: countUpDate.getSeconds(),
countUp: true
});
</script>
</body>
</html>