File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 1
1
2
2
3
- const loader = document . getElementById ( "loader" ) ;
4
3
function getQuote ( ) {
5
4
const quoteText = document . getElementById ( 'quoteText' ) ;
6
5
const characterName = document . getElementById ( 'characterName' ) ;
7
6
const imageUrl = document . querySelector ( ".image" ) ;
7
+ const loader = document . getElementById ( "loader" ) ;
8
+ const quoteBox = document . querySelector ( '.quote-box' ) ;
9
+ loader . style . display = "block" ;
10
+ imageUrl . classList . remove ( 'visible' ) ;
11
+ quoteBox . style . display = 'none' ;
8
12
fetch ( 'https://thesimpsonsquoteapi.glitch.me/quotes' )
9
13
. then ( response => response . json ( ) )
10
14
. then ( data => {
11
- console . log ( "=>(main.js:20) data" , data ) ;
15
+ quoteBox . style . display = 'block' ;
12
16
const quote = data [ 0 ] . quote ;
13
17
const character = data [ 0 ] . character ;
14
18
imageUrl . src = data [ 0 ] . image ;
@@ -19,5 +23,10 @@ function getQuote() {
19
23
. catch ( error => {
20
24
console . error ( 'Error fetching the quote:' , error ) ;
21
25
document . getElementById ( 'quoteText' ) . innerText = 'Failed to fetch quote. Please try again.' ;
22
- } ) ;
26
+ } )
27
+ . finally ( ( ) => {
28
+ loader . style . display = "none" ;
29
+ quoteBox . style . display = "block" ;
30
+ } ) ;
31
+
23
32
}
Original file line number Diff line number Diff line change 31
31
justify-content : center;
32
32
text-align : center;
33
33
width : 500px ;
34
+ min-height : 350px ;
34
35
}
35
36
# quoteText {
36
37
font-size : larger;
@@ -76,6 +77,7 @@ img.visible {
76
77
user-select : none;
77
78
-webkit-user-select : none;
78
79
touch-action : manipulation;
80
+ margin-bottom : 10px ;
79
81
}
80
82
81
83
.btn_class : focus {
@@ -106,14 +108,14 @@ img.visible {
106
108
107
109
.loader {
108
110
border : 8px solid # f3f3f3 ;
109
- border-top : 8px solid # 3498db ;
111
+ border-top : 8px solid # ff001a ;
110
112
border-radius : 50% ;
111
113
width : 60px ;
112
114
height : 60px ;
113
115
animation : spin 1s linear infinite;
114
- position : absolute;
116
+ /* position: absolute;*/
115
117
top : 50% ;
116
- left : 50 % ;
118
+ margin : 60 px auto 10 px auto ;
117
119
transform : translate (-50% , -50% );
118
120
display : none;
119
121
}
You can’t perform that action at this time.
0 commit comments