Skip to content

Commit a028ed4

Browse files
committed
[JS] Add simple timer example
1 parent d30aff3 commit a028ed4

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
body {
2+
font-family: sans-serif;
3+
}
4+
5+
p {
6+
padding: 8px;
7+
background-color: rgb(227, 227, 227);
8+
transition: 3s;
9+
}
10+
11+
p:nth-of-type(2) {
12+
color: rgb(255, 27, 27);
13+
}
14+
15+
.expand {
16+
padding: 40px;
17+
background-color: rgb(200, 200, 200);
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>JavaScript Examples | Timer (Example 1)</title>
6+
<link rel="stylesheet" href="css/style.css">
7+
</head>
8+
<body>
9+
<h1>JavaScript Examples | Timer (Example 1)</h1>
10+
<p>The following paragraph will expand, based on a class that is added then removed via two timers. The first timer waits a half a second to add a class, triggering the transition; the second waits three seconds to transition back by removing the class added by the first timer.</div>
11+
<p>I expand. Just wait a moment.</p>
12+
<p>See <a href="js/app.js">the JS</a> bound to this file.</p>
13+
<script src="js/app.js"></script>
14+
</body>
15+
</html>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*jslint browser, es6, single, devel */
2+
/*global window */
3+
4+
window.onload = function () {
5+
'use strict';
6+
7+
let p = document.getElementsByTagName('p');
8+
9+
setTimeout(function () {
10+
p[1].setAttribute('class', 'expand');
11+
}, 500);
12+
13+
setTimeout(function () {
14+
p[1].removeAttribute('class');
15+
}, 3500);
16+
};

0 commit comments

Comments
 (0)