index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { padding: 0; margin: 0; -webkit-box-sizing: border-box; box-sizing: border-box; } *:not(i) { font-family: "Poppins", sans-serif; } body { background-color: #ae9cff; } .wrapper { width: 92vmin; position: absolute; -webkit-transform: translateX(-50%); -ms-transform: translateX(-50%); transform: translateX(-50%); top: 50px; left: 50%; } .container { width: 100%; background-color: #ffffff; padding: 80px 50px; border-radius: 10px; -webkit-box-shadow: 0 20px 40px rgba(38, 33, 61, 0.2); box-shadow: 0 20px 40px rgba(38, 33, 61, 0.2); } a { padding: 15px 0; text-align: center; text-decoration: none; display: block; width: 100%; background-color: #ffffff; border-radius: 5px; color: #1f194c; font-weight: 600; -webkit-box-shadow: 0 20px 40px rgba(38, 33, 61, 0.2); box-shadow: 0 20px 40px rgba(38, 33, 61, 0.2); margin-top: 30px; } .search-box { width: 100%; display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; } .search-box input { padding: 5px; width: 70%; border: none; outline: none; border-bottom: 3px solid #ae9cff; } .search-box button { padding: 15px 0; width: 25%; background-color: #ae9cff; border: none; outline: none; color: #ffffff; border-radius: 5px; font-size: 16px; } .result { position: relative; } .result h3 { font-size: 30px; color: #1f194c; } .result .word { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-pack: justify; -ms-flex-pack: justify; justify-content: space-between; margin-top: 80px; } .result button { background-color: transparent; color: #ae9cff; border: none; outline: none; font-size: 18px; } .result .details { display: -webkit-box; display: -ms-flexbox; display: flex; gap: 10px; color: #b3b6d4; margin: 5px 0 20px 0; font-size: 14px; } .word-meaning { color: #575a7b; } .word-example { color: #575a7b; font-style: italic; border-left: 5px solid #ae9cff; padding-left: 20px; margin-top: 30px; font-size: 16px; } .error { margin-top: 80px; text-align: center; } @media screen and (max-width: 768px) { .container { padding: 40px 20px; } .search-box button { font-size: 14px; } } </style> </head> <body> <div class="wrapper"> <audio id="sound"></audio> <div class="container"> <div class="search-box"> <input type="text" placeholder="Type the word here..." id="inp-word" /> <button id="search-btn">Search</button> </div> <div id="result" class="result"></div> </div> </div> </body> <script> const url = "https://api.dictionaryapi.dev/api/v2/entries/en/"; const result = document.getElementById("result"); const sound = document.getElementById("sound"); const btn = document.getElementById("search-btn"); btn.addEventListener("click", () => { let inpWord = document.getElementById("inp-word").value; fetch(`${url}${inpWord}`) .then((response) => { return response.json(); }) .then((data) => { result.innerHTML = ` <div class="word"> <h3>${inpWord}</h3> <button onclick="playSound()"> <i class="fas fa-volume-up"></i></button> </div> <div class="details"> <p>${data[0].meanings[0].partOfSpeech}</p> <p>/${data[0].phonetic}/</p> </div> <p class="word-meaning"> ${data[0].meanings[0].definitions[0].definition} </p> <p class="word-example">${ data[0].meanings[0].definitions[0].example || "" }</p> `; sound.setAttribute("src", `https:${data[0].phonetics[0].audio}`); }) .catch((error) => { result.innerHTML = `<h3 class="error">Couldn't Find The Word!</h3>`; }); }); function playSound() { sound.play(); } </script> </html> |