display.html 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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: 3em;
  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. font-size: 2em;
  40. text-decoration: underline;
  41. }
  42. .weatherBlock img{
  43. height: 10vw;
  44. width: 10vw;
  45. }
  46. .condition{
  47. margin-right: 35px;
  48. }
  49. .conditionText{
  50. text-align: center;
  51. }
  52. .weatherInfo{
  53. display: flex;
  54. flex-direction: column;
  55. justify-content: space-between;
  56. height: 100%;
  57. padding: 15px 0;
  58. }
  59. .weatherInfo p{
  60. font-size: 1.3em;
  61. }
  62. </style>
  63. </head>
  64. <body>
  65. <div class="dateTime">
  66. <p id="date"></p>
  67. <p id="time"></p>
  68. </div>
  69. <div class="weather">
  70. <div id="currentWeather" class="weatherBlock">
  71. <h2>Current Weather</h2>
  72. <div class="condition">
  73. <img>
  74. <p class="conditionText"></p>
  75. </div>
  76. <div class="weatherInfo">
  77. <p id="temp"></p>
  78. <p id="feels"></p>
  79. <p id="wind"></p>
  80. <p id="humidity"</p>
  81. </div>
  82. </div>
  83. </div>
  84. </body>
  85. <script>
  86. const setDateTime = ()=>{
  87. const dateTime = new Date();
  88. document.getElementById("date").textContent = dateTime.toLocaleDateString("en-US", {
  89. weekday: "long",
  90. year: "numeric",
  91. month: "long",
  92. day: "numeric"
  93. });
  94. document.getElementById("time").textContent = dateTime.toLocaleTimeString("en-US", {
  95. hour: "numeric",
  96. minute: "2-digit",
  97. hour12: true
  98. });
  99. }
  100. const getWeather = ()=>{
  101. fetch("https://api.weatherapi.com/v1/current.json?key=519f51763fa8477b864184849251502&q=29576&aqi=no", {
  102. method: "get"
  103. })
  104. .then(r=>r.json())
  105. .then((response)=>{
  106. const tempDisplay = `Temperature: ${response.current.temp_f}\u00B0F`;
  107. document.getElementById("temp").textContent = tempDisplay;
  108. const feelsLike = `Feels Like: ${response.current.feelslike_f}\u00B0F`;
  109. document.getElementById("feels").textContent = feelsLike;
  110. const currentWeatherImage = document.querySelector("#currentWeather img");
  111. currentWeatherImage.src = `https:${response.current.condition.icon}`;
  112. currentWeatherImage.alt = response.current.condition.text;
  113. const currentWeatherText = document.querySelector("#currentWeather .conditionText");
  114. currentWeatherText.textContent = response.current.condition.text;
  115. const currentWind = `Wind: ${response.current.wind_mph}mph ${response.current.wind_dir}`;
  116. document.getElementById("wind").textContent = currentWind;
  117. const humidity = `Humidity: ${response.current.humidity}%`;
  118. document.getElementById("humidity").textContent = humidity;
  119. })
  120. .catch((err)=>{
  121. console.log(err);
  122. });
  123. }
  124. getWeather();
  125. setInterval(getWeather, 60000);
  126. setDateTime();
  127. setInterval(setDateTime, 10000);
  128. </script>
  129. </html>