Skip to content

Instantly share code, notes, and snippets.

@mattborn
Last active June 7, 2016 01:56
Show Gist options
  • Select an option

  • Save mattborn/51bfbf86f5df00000fbc205aba9c511e to your computer and use it in GitHub Desktop.

Select an option

Save mattborn/51bfbf86f5df00000fbc205aba9c511e to your computer and use it in GitHub Desktop.
ClockBlock™

Design as desire.

I want this app to…

  • display the current time.
  • display the current week of the year.
  • display all the days of the current week.
<!doctype html>
<html>
<head>
<title>ClockBlock™</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="lines"></div>
<div class="minute"></div>
<div class="week"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="scripts.js"></script>
</body>
</html>
var m = moment();
var elapsed = m.clone().diff(m.clone().startOf('day'), 'minutes') / 1440 * 100 + '%';
var el = document.querySelector('.minute');
var lines = document.querySelector('.lines');
var week = document.querySelector('.week');
for (var i = 1; i < 24; i++) {
lines.innerHTML += '<div class="line" style="top:'+ i * 100 / 24 +'%"></div>';
}
for (var d = 0; d < 7; d++) {
week.innerHTML += '<h1>'+ m.clone().startOf('week').add(d, 'day').format('D dd') +'</h1>';
}
// console.log('elapsed', elapsed);
setInterval(function () {
el.innerText = moment().format('h:mm:ss a') + ' Week: '+ m.format('w');
el.style.top = elapsed;
}, 1000);
body {
margin: 0;
}
.lines {
height: 100vh;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.line {
border-top: 1px solid #eee;
left: 0;
position: absolute;
width: 100%;
}
.minute {
border-style: solid;
border-width: 1px 0 0;
left: 0;
padding: 2px 2px 2px 10px;
position: absolute;
top: 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment