JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<!--
RE:DOM view library: https://redom.js.org
-->
<script src="https://redom.js.org/redom.min.js"></script>
@import 'nib';
* {
margin: 0;
padding: 0;
}
html {
text-size-adjust: 100%;
}
body {
font-family: sans-serif;
padding: 2rem 1.5rem;
background-color: #f9f9f9;
color: #333;
}
.progress {
max-width: 50rem;
margin: 0 auto;
}
.progress .percent {
float: right;
font-size: 0.75rem;
font-weight: 600;
font-variant-numeric: tabular-nums;
}
.progress .label {
font-weight: 600;
}
.progress .barbg {
background-color: #ddd;
}
.progress .bar {
height: 0.25rem;
background-color: #444;
margin-top: 0.5rem;
transform-origin: 0 0;
}
.progress + .progress {
margin-top: 1.25rem;
padding-top: 0.5rem;
}
@media (max-width: 480px) {
html {
font-size: 75%;
}
}
@media (max-width: 640px) {
html {
font-size: 87.5%;
}
}
@media (min-width: 1280px) {
html {
font-size: 112.5%;
}
}
@media (min-width: 1600px) {
html {
font-size: 125%;
}
}
const { el, text, setChildren } = redom;
class Progress {
constructor (name, precision) {
this.precision = precision || 0;
this.el = el('.progress',
el('.percent',
this.percent = text('')
),
el('.label', name),
el('.barbg',
this.bar = el('.bar')
)
);
}
update (progress) {
const { precision } = this;
const percent = progress * 100;
this.percent.textContent = percent.toFixed(precision) + ' %';
this.bar.style.transform = 'scale(' + progress + ', 1)';
}
}
const second = new Progress('Second');
const minute = new Progress('Minute', 1);
const hour = new Progress('Hour', 2);
const day = new Progress('Day', 3);
const week = new Progress('Week (monday-first)', 4);
const month = new Progress('Month', 5);
const year = new Progress('Year', 6);
setChildren(document.body, [second, minute, hour, day, week, month, year].reverse());
const SECOND = 1000;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
function render () {
requestAnimationFrame(render);
const now = Date.now();
second.update((now % SECOND) / SECOND);
minute.update((now % MINUTE) / MINUTE);
hour.update((now % HOUR) / HOUR);
day.update(getDayProgress(now));
week.update(getWeekProgress(now));
month.update(getMonthProgress(now));
year.update(getYearProgress(now));
}
render();
function getDayProgress (now) {
const startOfDay = new Date();
resetDate(startOfDay);
const endOfDay = new Date(startOfDay);
endOfDay.setDate(endOfDay.getDate() + 1);
return (now - startOfDay) / (endOfDay - startOfDay);
}
function getWeekProgress (now) {
const startOfWeek = new Date();
const day = (startOfWeek.getDay() - 1) % 7;
startOfWeek.setDate(startOfWeek.getDate() - day);
resetDate(startOfWeek);
const endOfWeek = new Date(startOfWeek);
endOfWeek.setDate(endOfWeek.getDate() + 7);
return (now - startOfWeek) / (endOfWeek - startOfWeek);
}
function getMonthProgress (now) {
const startOfMonth = new Date();
startOfMonth.setDate(1);
resetDate(startOfMonth);
const endOfMonth = new Date(startOfMonth);
endOfMonth.setMonth(endOfMonth.getMonth() + 1);
return (now - startOfMonth) / (endOfMonth - startOfMonth);
}
function resetDate (date) {
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);
date.setMilliseconds(0);
}
function getYearProgress (now) {
const startOfYear = new Date();
resetDate(startOfYear);
startOfYear.setDate(1);
startOfYear.setMonth(0);
const endOfYear = new Date(startOfYear);
endOfYear.setFullYear(endOfYear.getFullYear() + 1);
return (now - startOfYear) / (endOfYear - startOfYear);
}
Also see: Tab Triggers