File tree Expand file tree Collapse file tree 3 files changed +122
-0
lines changed Expand file tree Collapse file tree 3 files changed +122
-0
lines changed Original file line number Diff line number Diff line change 1+ const upload = document . querySelector ( "input" ) ;
2+ const image = document . querySelector ( ".img img" ) ;
3+ const close = document . querySelector ( ".icon .close" ) ;
4+
5+ upload . addEventListener ( "change" , ( ) => {
6+ uploadFile ( event ) ;
7+ } ) ;
8+
9+ function uploadFile ( event ) {
10+ image . classList . add ( "active" ) ;
11+ close . classList . add ( "exit" ) ;
12+
13+ image . src = URL . createObjectURL ( event . target . files [ 0 ] ) ;
14+
15+ close . addEventListener ( "click" , ( ) => {
16+ image . classList . toggle ( "active" ) ;
17+ close . classList . toggle ( "exit" ) ;
18+ } ) ;
19+ }
Original file line number Diff line number Diff line change 1+ < html lang ="en ">
2+ < head >
3+ < meta charset ="UTF-8 " />
4+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
6+ < title > Browse File Upload</ title >
7+ < link rel ="stylesheet " href ="style.css " />
8+ </ head >
9+ < body >
10+ < section class ="wrapper ">
11+ < div class ="icon ">
12+ < p class ="close "> ✖</ p >
13+ </ div >
14+ < h2 class ="text "> Upload a file from your computer!</ h2 >
15+ < div class ="img ">
16+ < img src ="" />
17+ </ div >
18+ < input type ="file " id ="file " />
19+ < label for ="file " class ="upload "> Browse File</ label >
20+ </ section >
21+
22+ < script src ="app.js "> </ script >
23+ </ body >
24+ </ html >
Original file line number Diff line number Diff line change 1+ * {
2+ padding : 0 ;
3+ margin : 0 ;
4+ box-sizing : border-box;
5+ font-family : sans-serif;
6+ }
7+
8+ body {
9+ min-height : 100vh ;
10+ background-color : crimson;
11+ display : flex;
12+ flex-direction : column;
13+ justify-content : center;
14+ align-items : center;
15+ }
16+
17+ .wrapper {
18+ max-width : 700px ;
19+ height : 500px ;
20+ width : 100% ;
21+ border : 2px dashed white;
22+ text-align : center;
23+ position : relative;
24+ overflow : hidden;
25+ }
26+
27+ .text {
28+ margin-bottom : 25px ;
29+ color : # fff ;
30+ }
31+
32+ input {
33+ display : none;
34+ }
35+
36+ .upload {
37+ background : white;
38+ padding : 8px 20px ;
39+ transition : 0.4s ease;
40+ cursor : pointer;
41+ }
42+
43+ .upload : hover {
44+ box-shadow : 0 4px 2px rgba (0 , 0 , 0 , 0.2 );
45+ }
46+
47+ .img img {
48+ width : 99% ;
49+ height : 99% ;
50+ object-fit : cover;
51+ position : absolute;
52+ top : 2px ;
53+ left : 2px ;
54+ display : none;
55+ }
56+
57+ .icon p .close {
58+ font-size : 20px ;
59+ color : # fff ;
60+ position : absolute;
61+ right : 20px ;
62+ top : 10px ;
63+ z-index : 1 ;
64+ display : none;
65+ cursor : pointer;
66+ }
67+
68+ .wrapper .icon p .close : hover {
69+ color : crimson;
70+ }
71+
72+ /* JavaScript */
73+ .img img .active {
74+ display : block;
75+ }
76+
77+ .wrapper .icon p .close .exit {
78+ display : block;
79+ }
You can’t perform that action at this time.
0 commit comments