File tree Expand file tree Collapse file tree 3 files changed +147
-0
lines changed
Expand file tree Collapse file tree 3 files changed +147
-0
lines changed Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head >
4+ < meta charset ="UTF-8 ">
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6+ < title > Document</ title >
7+
8+ <!-- css -->
9+ < link rel ="stylesheet " href ="styles.css ">
10+
11+ </ head >
12+
13+ < body >
14+
15+ < header id ="navbar ">
16+ < nav >
17+ < h1 class ="navbar-title "> Test Your Display</ h1 >
18+ </ nav >
19+ </ header >
20+
21+ < div id ="canvas ">
22+ < h3 > Press start to see the color change and Stop to stop it.</ h3 >
23+ < button id ="start "> Start</ button >
24+ < button id ="stop "> Stop</ button >
25+ </ div >
26+
27+
28+ </ body >
29+
30+ < script src ="script.js "> </ script >
31+ </ html >
Original file line number Diff line number Diff line change 1+ const start = document . querySelector ( '#start' ) ;
2+ const stop = document . querySelector ( '#stop' ) ;
3+ const body = document . querySelector ( 'body' )
4+
5+ let startInterval ;
6+
7+
8+ // Hex color code generator.
9+ let hex = '0123456789abcdef' ;
10+ const colorId = function ( ) {
11+ let colorHex = "#" ;
12+ for ( let i = 0 ; i < 6 ; i ++ ) {
13+ colorHex += hex [ Math . floor ( Math . random ( ) * 16 ) ] ;
14+ }
15+
16+ return colorHex
17+ } ;
18+
19+
20+
21+ // color setter
22+ const changeColor = function ( ) {
23+ body . style . backgroundColor = colorId ( ) ;
24+ }
25+
26+
27+ let intervalId ;
28+ // color change start
29+ startInterval = function ( ) {
30+ if ( ! intervalId ) {
31+ intervalId = setInterval ( changeColor , 1000 ) ;
32+ }
33+ } ;
34+
35+ // start button click
36+ start . addEventListener ( 'click' , startInterval ) ;
37+
38+
39+
40+ // color change stop
41+ let stopInterval = function ( ) {
42+ clearInterval ( intervalId ) ;
43+ intervalId = null ;
44+ } ;
45+
46+ // stop button click
47+ stop . addEventListener ( 'click' , stopInterval ) ;
48+
49+
Original file line number Diff line number Diff line change 1+ * {
2+ margin : 0 ;
3+ padding : 0 ;
4+ box-sizing : border-box;
5+ }
6+
7+ body {
8+ font-family : 'Franklin Gothic Medium' , 'Arial Narrow' , Arial, sans-serif;
9+
10+ display : flex;
11+ flex-direction : column;
12+ justify-content : center;
13+ align-items : center;
14+ height : 80vh ;
15+ gap : 1em ;
16+ }
17+
18+ button {
19+ padding : 10px 20px ;
20+ font-size : 1rem ;
21+ cursor : pointer;
22+ background-color : transparent;
23+ border-radius : 5px ;
24+ border : 2px solid rgb (226 , 110 , 226 );
25+ color : chartreuse;
26+ font-weight : bolder;
27+ }
28+
29+ button : hover {
30+ background-color : cornflowerblue;
31+ }
32+
33+ .navbar-title {
34+ padding : 20px 0 ;
35+ text-align : center;
36+ }
37+
38+ # navbar {
39+ display : flex;
40+ justify-content : center;
41+ align-items : center;
42+ }
43+
44+ # canvas {
45+ display : flex;
46+ flex-direction : column;
47+ justify-content : center;
48+ align-items : center;
49+ height : 80vh ;
50+ gap : 1em ;
51+ }
52+
53+ @media (max-width : 768px ) {
54+ # canvas {
55+ flex-wrap : wrap;
56+ max-width : 400px ;
57+ text-align : center;
58+ }
59+ }
60+
61+ @media (max-width : 500px ) {
62+ # canvas {
63+ flex-wrap : wrap;
64+ max-width : 250px ;
65+ text-align : center;
66+ }
67+ }
You can’t perform that action at this time.
0 commit comments