File tree Expand file tree Collapse file tree 4 files changed +156
-2
lines changed Expand file tree Collapse file tree 4 files changed +156
-2
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+ < link rel ="stylesheet " href ="style.css " />
7+ < title > Live User Filter</ title >
8+ </ head >
9+ < body >
10+ < div class ="container ">
11+ < header class ="header ">
12+ < h4 class ="title "> Live User Filter</ h4 >
13+ < small class ="subtitle "> Search by name and/or location</ small >
14+ < input type ="text " name ="filter " id ="filter " placeholder ="Search " />
15+ </ header >
16+ < ul id ="result " class ="user-list ">
17+ < li > < h3 > Loading...</ h3 > </ li >
18+ </ ul >
19+ </ div >
20+ < script src ="script.js "> </ script >
21+ </ body >
22+ </ html >
Original file line number Diff line number Diff line change 1+ const result = document . getElementById ( "result" ) ;
2+ const filter = document . getElementById ( "filter" ) ;
3+ const listItems = [ ] ;
4+
5+ const filterData = ( searchTerm ) => {
6+ listItems . forEach ( ( item ) => {
7+ if ( item . innerText . toLowerCase ( ) . includes ( searchTerm . toLowerCase ( ) ) ) {
8+ item . classList . remove ( "hide" ) ;
9+ } else {
10+ item . classList . add ( "hide" ) ;
11+ }
12+ } ) ;
13+ } ;
14+
15+ const getData = async ( ) => {
16+ const res = await fetch ( "https://randomuser.me/api?results=50" ) ;
17+ const { results } = await res . json ( ) ;
18+ result . innerHTML = "" ;
19+ results . forEach ( ( user ) => {
20+ const li = document . createElement ( "li" ) ;
21+ listItems . push ( li ) ;
22+ li . innerHTML = `
23+ <img
24+ src="${ user . picture . large } "
25+ alt="${ user . name . first } "
26+ />
27+ <div class="user-info">
28+ <h4>${ user . name . first } ${ user . name . last } </h4>
29+ <p>${ user . location . city } , ${ user . location . country } </p>
30+ </div>
31+ ` ;
32+ result . appendChild ( li ) ;
33+ } ) ;
34+ } ;
35+
36+ getData ( ) ;
37+
38+ filter . addEventListener ( "input" , ( e ) => filterData ( e . target . value ) ) ;
Original file line number Diff line number Diff line change 1+ @import url ("https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" );
2+
3+ * {
4+ box-sizing : border-box;
5+ }
6+
7+ body {
8+ background-color : # f8f9fd ;
9+ font-family : "Roboto" , sans-serif;
10+ display : flex;
11+ align-items : center;
12+ justify-content : center;
13+ height : 100vh ;
14+ overflow : hidden;
15+ margin : 0 ;
16+ }
17+
18+ .container {
19+ border-radius : 5px ;
20+ box-shadow : 3px 3px 10px rgba (0 , 0 , 0 , 0.2 );
21+ overflow : hidden;
22+ width : 300px ;
23+ }
24+
25+ .title {
26+ margin : 0 ;
27+ }
28+
29+ .subtitle {
30+ display : inline-block;
31+ margin : 5px 0 20px ;
32+ opacity : 0.8 ;
33+ }
34+
35+ .header {
36+ background-color : # 3e57db ;
37+ color : # fff ;
38+ padding : 30px 20px ;
39+ }
40+
41+ .header input {
42+ background-color : rgba (0 , 0 , 0 , 0.3 );
43+ border : 0 ;
44+ border-radius : 50px ;
45+ color : # fff ;
46+ font-size : 14px ;
47+ padding : 10px 15px ;
48+ width : 100% ;
49+ }
50+
51+ .header input : focus {
52+ outline : none;
53+ }
54+
55+ .user-list {
56+ background-color : # fff ;
57+ list-style-type : none;
58+ margin : 0 ;
59+ padding : 0 ;
60+ max-height : 400px ;
61+ overflow-y : auto;
62+ }
63+
64+ .user-list li {
65+ display : flex;
66+ padding : 20px ;
67+ }
68+
69+ .user-list img {
70+ border-radius : 50% ;
71+ object-fit : cover;
72+ height : 50px ;
73+ width : 50px ;
74+ }
75+
76+ .user-list .user-info {
77+ margin-left : 10px ;
78+ }
79+
80+ .user-list .user-info h4 {
81+ margin : 0 0 10px ;
82+ }
83+
84+ .user-list .user-info p {
85+ font-size : 12px ;
86+ }
87+
88+ .user-list li : not (: last-of-type ) {
89+ border-bottom : 1px solid # eee ;
90+ }
91+
92+ .user-list li .hide {
93+ display : none;
94+ }
Original file line number Diff line number Diff line change 4242| 34 | [ Animated Countdown] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/34-animated%20countdown ) | [ Live Demo] ( https://codepen.io/solygambas/full/vYXPbYW ) |
4343| 35 | [ Image Carousel] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/35-image%20carousel ) | [ Live Demo] ( https://codepen.io/solygambas/full/zYKbQZK ) |
4444| 36 | [ Hoverboard] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/36-hoverboard ) | [ Live Demo] ( https://codepen.io/solygambas/full/OJRqYKK ) |
45- | 37 | [ Pokedex] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/37-pokedex ) | [ Live Demo] ( /pokedex/ ) |
45+ | 37 | [ Pokedex] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/37-pokedex ) | [ Live Demo] ( https://codepen.io/solygambas/full/gOwygyP ) |
4646| 38 | [ Mobile Tab Navigation] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/mobile-tab-navigation ) | [ Live Demo] ( /mobile-tab-navigation/ ) |
4747| 39 | [ Password Strength Background] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/password-strength-background ) | [ Live Demo] ( /password-strength-background/ ) |
4848| 40 | [ 3D Background Boxes] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/40-3d%20boxes%20background ) | [ Live Demo] ( /3d-background-boxes/ ) |
4949| 41 | [ Verify Account UI] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/verify-account-ui ) | [ Live Demo] ( /verify-account-ui/ ) |
50- | 42 | [ Live User Filter] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/live-user-filter ) | [ Live Demo] ( /live-user-filter/ ) |
50+ | 42 | [ Live User Filter] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/42-live%20user%20filter ) | [ Live Demo] ( /live-user-filter/ ) |
5151| 43 | [ Feedback UI Design] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/feedback-ui-design ) | [ Live Demo] ( /feedback-ui-design/ ) |
5252| 44 | [ Custom Range Slider] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/custom-range-slider ) | [ Live Demo] ( /custom-range-slider/ ) |
5353| 45 | [ Netflix Mobile Navigation] ( https://github.com/solygambas/html-css-fifty-projects/tree/master/netflix-mobile-navigation ) | [ Live Demo] ( /netflix-mobile-navigation/ ) |
You can’t perform that action at this time.
0 commit comments