Skip to content

Commit 52b3f07

Browse files
committed
Random User Avatar Generator
1 parent 0e2c3ca commit 52b3f07

File tree

4 files changed

+170
-0
lines changed

4 files changed

+170
-0
lines changed
64.1 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Random User Card Generator</title>
8+
<link rel="stylesheet" href="style.css">
9+
<script defer src="script.js"></script>
10+
</head>
11+
12+
<body>
13+
<div class="container">
14+
<div class="card">
15+
<div class="image-container" id="image-container">
16+
<div class="details" id="details">
17+
<img src="" alt="" id="image">
18+
<h2 id="userName"></h2>
19+
<h2 id="first-name"></h2>
20+
<h2 id="last-name"></h2>
21+
<h2 id="email"></h2>
22+
<button class="get-random-user-btn">Get Radom User</button>
23+
</div>
24+
</div>
25+
</div>
26+
27+
</div>
28+
</body>
29+
</html>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const imageContainer = document.getElementById('image-container');
2+
const details = document.getElementById('details');
3+
const url = 'https://random-data-api.com/api/v2/users?response_type=json'
4+
const firstName = document.getElementById('first-name');
5+
const lastName = document.getElementById('last-name');
6+
const image = document.getElementById('image');
7+
const email = document.getElementById('email');
8+
const userName = document.getElementById('userName');
9+
const getBtn = document.querySelector('.get-random-user-btn');
10+
11+
let getUser = () => {
12+
// fetch(url).then(resp => resp.json()).then(data => console.log(data.first_name,data.last_name))
13+
// fetch(url).then(resp => resp.json()).then(data => console.log(data))
14+
fetch(url).then(resp => resp.json()).then(data => {
15+
16+
17+
18+
userName.innerText = data.username;
19+
image.src = data.avatar;
20+
firstName.innerHTML = data.first_name;
21+
lastName.innerHTML = data.last_name;
22+
email.innerText = data.email;
23+
24+
25+
})
26+
}
27+
getUser(url)
28+
29+
getBtn.addEventListener('click', getUser)
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
box-sizing: border-box;
5+
}
6+
7+
.container {
8+
display: flex;
9+
justify-content: center;
10+
align-items: center;
11+
position: absolute;
12+
top: 50%;
13+
left: 50%;
14+
transform: translate(-50%, -50%);
15+
width: 100%;
16+
height: 100%;
17+
background: #05386b;
18+
overflow: hidden;
19+
margin: 0px;
20+
21+
22+
}
23+
24+
.card {
25+
width: 300px;
26+
height: 400px;
27+
background: #fff;
28+
border-radius: 10px;
29+
box-shadow: 0 15px 35px rgba(50, 50, 93, .1), 0 5px 15px rgba(0, 0, 0, .07);
30+
31+
32+
33+
}
34+
35+
.image-container {
36+
display: flex;
37+
justify-content: center;
38+
align-items: center;
39+
height: 100%;
40+
position: absolute;
41+
top: 50%;
42+
left: 50%;
43+
transform: translate(-50%, -50%);
44+
45+
}
46+
47+
.details {
48+
display: flex;
49+
flex-direction: column;
50+
justify-content: center;
51+
align-items: center;
52+
53+
}
54+
55+
#userName {
56+
margin-top: 10px;
57+
font-size: 20px;
58+
font-weight: 500;
59+
color: #05386b;
60+
61+
}
62+
63+
#first-name {
64+
margin-top: 10px;
65+
font-size: 20px;
66+
font-weight: 500;
67+
color: #05386b;
68+
69+
}
70+
71+
#last-name {
72+
margin-top: 10px;
73+
font-size: 20px;
74+
font-weight: 500;
75+
color: #05386b;
76+
77+
}
78+
79+
#image {
80+
width: 100px;
81+
height: 100px;
82+
border-radius: 50%;
83+
object-fit: cover;
84+
margin-top: 5px;
85+
86+
}
87+
88+
#email {
89+
margin-top: 10px;
90+
font-size: 20px;
91+
font-weight: 500;
92+
color: #05386b;
93+
94+
95+
}
96+
97+
.get-random-user-btn {
98+
width: 100%;
99+
height: 50px;
100+
background: #05386b;
101+
color: #fff;
102+
border: none;
103+
outline: none;
104+
border-radius: 5px;
105+
font-size: 18px;
106+
font-weight: 500;
107+
cursor: pointer;
108+
margin-top: 10px;
109+
transition: all 0.3s ease;
110+
margin-bottom: -50px;
111+
112+
}

0 commit comments

Comments
 (0)