change color and icon to match iqair
This commit is contained in:
parent
08fbf9fe02
commit
a8e40f9cd8
2 changed files with 141 additions and 51 deletions
|
@ -77,6 +77,25 @@
|
|||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
:root {
|
||||
--good-color: #ABD162;
|
||||
--moderate-color: #F7D460;
|
||||
--unhealthy-sensitive-color: #FD9760;
|
||||
--unhealthy-color: #F7666E;
|
||||
--very-unhealthy-color: #A37CBB;
|
||||
--hazardous-color: #A07685;
|
||||
--icon-good: /images/aqi-icon-l1.svg;
|
||||
--icon-moderate: /images/aqi-icon-l2.svg;
|
||||
--icon-unhealthy-sensitive: /images/aqi-icon-l3.svg;
|
||||
--icon-unhealthy: /images/aqi-icon-l4.svg;
|
||||
--icon-very-unhealthy: /images/aqi-icon-l5.svg;
|
||||
--icon-hazardous: /images/aqi-icon-l6.svg;
|
||||
}
|
||||
#health_icon {
|
||||
transform: scale(1.7);
|
||||
padding-top: 15px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
|
@ -85,7 +104,7 @@
|
|||
<div class="aqi_block" id="top_element">
|
||||
<p class="aqi_text" id="outdoor-aqi">0</p>
|
||||
</div>
|
||||
<span class="iconify" data-icon="mdi-heart" id="health_icon"></span>
|
||||
<img id="health_icon" src="">
|
||||
<p class="health_text" , id="health_text">Healthy</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -129,35 +148,51 @@
|
|||
$("#outdoor-aqi").text("AQI : "+data.aqi_outdoor);
|
||||
|
||||
// Is outdoor AQI healthy?
|
||||
// If AQI is less than 50, it is healthy
|
||||
// If AQI is between 50 and 100, it is unhealthy
|
||||
// If AQI is more than 100, it is very unhealthy
|
||||
var oldIcon = document.getElementById("health_icon");
|
||||
oldIcon.parentNode.removeChild(oldIcon);
|
||||
var newIcon = document.createElement("span");
|
||||
newIcon.setAttribute("class", "iconify");
|
||||
|
||||
newIcon.setAttribute("data-inline", "false");
|
||||
newIcon.id = "health_icon";
|
||||
// If AQI is less than 50, it is good
|
||||
// If AQI is between 50 and 100, it is moderate
|
||||
// If AQI is between 100 and 150, it is unhealthy for sensitive groups
|
||||
// If AQI is between 150 and 200, it is unhealthy
|
||||
// If AQI is between 200 and 300, it is very unhealthy
|
||||
// If AQI is more than 300, it is hazardous
|
||||
let root = document.documentElement;
|
||||
let root_css = getComputedStyle(root);
|
||||
if (data.aqi_outdoor < 50) {
|
||||
newIcon.setAttribute("data-icon", "mdi-heart");
|
||||
Iconify.scanDOM();
|
||||
let icon_path = root_css.getPropertyValue('--icon-good').trim();
|
||||
let bg_color = root_css.getPropertyValue('--good-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Healthy");
|
||||
$("#health_icon_frame").css("background-color", "#7bdb3f");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 50 && data.aqi_outdoor < 100) {
|
||||
newIcon.setAttribute("data-icon", "mdi-smog");
|
||||
Iconify.scanDOM();
|
||||
let icon_path = root_css.getPropertyValue('--icon-moderate').trim();
|
||||
let bg_color = root_css.getPropertyValue('--moderate-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Moderate");
|
||||
$("#health_icon_frame").css("background-color", "#f9c300");
|
||||
} else {
|
||||
newIcon.setAttribute("data-icon", "mdi-skull-crossbones");
|
||||
Iconify.scanDOM();
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 100 && data.aqi_outdoor < 150) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-unhealthy-sensitive').trim();
|
||||
let bg_color = root_css.getPropertyValue('--unhealthy-sensitive-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Unhealthy for Sensitive Groups");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 150 && data.aqi_outdoor < 200) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-unhealthy').trim();
|
||||
let bg_color = root_css.getPropertyValue('--unhealthy-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Unhealthy");
|
||||
$("#health_icon_frame").css("background-color", "#A54444");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 200 && data.aqi_outdoor < 300) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-very-unhealthy').trim();
|
||||
let bg_color = root_css.getPropertyValue('--very-unhealthy-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Very Unhealthy");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
} else if (data.aqi_outdoor >= 300) {
|
||||
let icon_path = root_css.getPropertyValue('--icon-hazardous').trim();
|
||||
let bg_color = root_css.getPropertyValue('--hazardous-color').trim();
|
||||
$("#health_icon").attr("src", icon_path);
|
||||
$("#health_text").text("Hazardous");
|
||||
$("#health_icon_frame").css("background-color", bg_color);
|
||||
}
|
||||
|
||||
document.getElementById("health_icon_frame").appendChild(newIcon);
|
||||
Iconify.scanDOM();
|
||||
});
|
||||
}
|
||||
else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue