Skip to content

Commit f60e2da

Browse files
Merge pull request #2 from Pritish4113/main
Adding a feature and improving overall UI
2 parents 563adae + 72692c1 commit f60e2da

File tree

3 files changed

+76
-12
lines changed

3 files changed

+76
-12
lines changed

color-changing-app-main/color-changing-app-main/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
let colors = [ 'red', 'blue', 'green', 'orange', 'purple', 'black', 'yellow'];
33

44

5-
65
//change the background of canvas when button is clicked
76
let button = document.getElementById('button');
7+
let canvas = document.getElementById('canvas');
8+
9+
function bgchange(color){
10+
canvas.style.backgroundColor = color;
11+
}
812

913
button.addEventListener('click', function(){
1014
//select a random number between 0 - 6
1115
let index = parseInt((Math.random()*colors.length)+1);
12-
//grab the canvas
13-
let canvas = document.getElementById('canvas');
1416

1517
canvas.style.background = `${colors[index]}`
1618
})

color-changing-app-main/color-changing-app-main/index.html

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,23 @@
88
<title>JavaScript Color Changing App</title>
99
</head>
1010
<body>
11-
<div id="canvas">
12-
My background color will change when my button below is clicked.
13-
</div>
11+
<div class="container">
12+
<div id="canvas">
13+
My background color will change when my button below is clicked.
14+
</div>
15+
16+
<button id="button">Click me!</button>
1417

15-
<button id="button">Click me!</button>
18+
<div class="exactcolor">
19+
<span onclick="bgchange('#ff0000')" id = 'red' class = 'colorbutton'></span>
20+
<span onclick="bgchange('#0000ff')" id = 'blue' class = 'colorbutton'></span>
21+
<span onclick="bgchange('#008000')" id = 'green' class = 'colorbutton'></span>
22+
<span onclick="bgchange('#ffa500')" id = 'orange' class = 'colorbutton'></span>
23+
<span onclick="bgchange('#800080')" id = 'purple' class = 'colorbutton'></span>
24+
<span onclick="bgchange('#000000')" id = 'black' class = 'colorbutton'></span>
25+
<span onclick="bgchange('#ffff00')" id = 'yellow' class = 'colorbutton'></span>
26+
</div>
27+
</div>
1628

1729

1830

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,76 @@
1+
html{
2+
background-image: linear-gradient(120deg, #5f57d1, #c065c0);
3+
}
4+
5+
.container{
6+
min-height: 100vh;
7+
}
8+
19
#canvas{
2-
background-color: red;
3-
color: white;
10+
background-color: white;
11+
color: black;
412
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
5-
font-size: 25px;
13+
font-size: 23px;
14+
font-weight: bold;
615
width: 600px;
716
height: 500px;
817
margin: 50px auto 50px;
918
text-align: center;
1019
display: flex;
1120
justify-content: center;
1221
align-items: center;
22+
border-radius: 10px;
1323
}
1424

1525
#button{
26+
cursor: pointer;
1627
text-align: center;
1728
width: 200px;
1829
height: 50px;
1930
margin: 50px auto 50px;
20-
color: white;
31+
color: black;
32+
font-weight: bold;
33+
font-size: 1.2rem;
2134
font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
22-
background: black;
35+
background: linear-gradient(-40deg,rgb(221, 106, 18),coral,rgb(255, 77, 77));
2336
border-radius: 5px;
2437
border-style: none;
2538
display: block;
39+
border-radius: 10px;
40+
}
41+
42+
.exactcolor{
43+
display: flex;
44+
justify-content: center;
45+
}
46+
47+
.colorbutton{
48+
cursor: pointer;
49+
margin: 5px;
50+
height: 30px;
51+
width: 30px;
52+
border-radius: 50%;
2653
}
54+
55+
#red{
56+
background-color: #ff0000;
57+
}
58+
#blue{
59+
background-color: #0000ff;
60+
}
61+
#green{
62+
background-color: #008000;
63+
}
64+
#orange{
65+
background-color: #ffa500;
66+
}
67+
#purple{
68+
background-color: #800080;
69+
}
70+
#black{
71+
background-color: #000000;
72+
}
73+
#yellow{
74+
background-color: #ffff00;
75+
}
76+

0 commit comments

Comments
 (0)