display.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <style>
  6. *{margin:0;padding:0;box-sizing:border-box}
  7. html, body{
  8. height: 100vh;
  9. }
  10. body{
  11. background: black;
  12. color: white;
  13. display: flex;
  14. flex-direction: column;
  15. justify-content: space-around;
  16. align-items: center;
  17. }
  18. .dateTime{
  19. display: flex;
  20. flex-direction: column;
  21. align-items: center;
  22. font-size: 32px;
  23. }
  24. .weatherBlock{
  25. display: flex;
  26. justify-content: space-between;
  27. align-items: center;
  28. position: relative;
  29. padding: 45px 15px 25px 15px;
  30. border: 1px solid white;
  31. height: 250px;
  32. }
  33. .weatherBlock h2{
  34. position: absolute;
  35. width: 100%;
  36. text-align: center;
  37. top: 15px;
  38. left: 0;
  39. }
  40. .weatherBlock img{
  41. height: 125px;
  42. width: 125px;
  43. }
  44. .condition{
  45. margin-right: 35px;
  46. }
  47. .conditionText{
  48. text-align: center;
  49. }
  50. .weatherInfo{
  51. display: flex;
  52. flex-direction: column;
  53. justify-content: space-between;
  54. height: 100%;
  55. padding: 15px 0;
  56. }
  57. .weatherInfo p{
  58. font-size: 18px;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <div class="dateTime">
  64. <p id="date"></p>
  65. <p id="time"></p>
  66. </div>
  67. <div class="weather">
  68. <div id="currentWeather" class="weatherBlock">
  69. <h2>Current Weather</h2>
  70. <div class="condition">
  71. <img>
  72. <p class="conditionText"></p>
  73. </div>
  74. <div class="weatherInfo">
  75. <p id="temp"></p>
  76. <p id="feels"></p>
  77. <p id="wind"></p>
  78. <p id="humidity"</p>
  79. </div>
  80. </div>
  81. </div>
  82. </body>
  83. <script>
  84. const setDateTime = ()=>{
  85. const dateTime = new Date();
  86. document.getElementById("date").textContent = dateTime.toLocaleDateString("en-US", {
  87. weekday: "long",
  88. year: "numeric",
  89. month: "long",
  90. day: "numeric"
  91. });
  92. document.getElementById("time").textContent = dateTime.toLocaleTimeString("en-US", {
  93. hour: "numeric",
  94. minute: "2-digit",
  95. hour12: true
  96. });
  97. }
  98. const getWeather = ()=>{
  99. fetch("https://api.weatherapi.com/v1/current.json?key=519f51763fa8477b864184849251502&q=29576&aqi=no", {
  100. method: "get"
  101. })
  102. .then(r=>r.json())
  103. .then((response)=>{
  104. const tempDisplay = `Temperature: ${response.current.temp_f}\u00B0F`;
  105. document.getElementById("temp").textContent = tempDisplay;
  106. const feelsLike = `Feels Like: ${response.current.feelslike_f}\u00B0F`;
  107. document.getElementById("feels").textContent = feelsLike;
  108. const currentWeatherImage = document.querySelector("#currentWeather img");
  109. currentWeatherImage.src = `https:${response.current.condition.icon}`;
  110. currentWeatherImage.alt = response.current.condition.text;
  111. const currentWeatherText = document.querySelector("#currentWeather .conditionText");
  112. currentWeatherText.textContent = response.current.condition.text;
  113. const currentWind = `Wind: ${response.current.wind_mph}mph ${response.current.wind_dir}`;
  114. document.getElementById("wind").textContent = currentWind;
  115. const humidity = `Humidity: ${response.current.humidity}%`;
  116. document.getElementById("humidity").textContent = humidity;
  117. })
  118. .catch((err)=>{
  119. console.log(err);
  120. });
  121. }
  122. getWeather();
  123. setInterval(getWeather, 60000);
  124. setDateTime();
  125. setInterval(setDateTime, 10000);
  126. </script>
  127. </html>