Skip to content

Instantly share code, notes, and snippets.

@ahmdrz
Created June 3, 2019 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmdrz/7799fdb2a0633d4094f4c31da1bbd2b7 to your computer and use it in GitHub Desktop.
Save ahmdrz/7799fdb2a0633d4094f4c31da1bbd2b7 to your computer and use it in GitHub Desktop.
<div class="battery">
<div id="battery_level" class="battery-level"></div>
</div>
<style>
.battery:after {
background-color: #fff;
border: 2px solid #000;
content: "";
display: block;
height: 16px;
position: absolute;
right: -6px;
top: 6px;
width: 6px;
}
.battery {
background-color: #fff;
border: 2px solid #000;
height: 32px;
position: fixed;
bottom: 10px;
left: 10px;
width: 100px;
}
.battery .battery-level {
background-color: #666;
height: 100%;
}
.battery .battery-level.high {
background-color: #66CD00;
}
.battery .battery-level.medium {
background-color: #FCD116;
}
.battery .battery-level.low {
background-color: #FF3333;
}
</style>
<script>
function setBatteryLevel(level) {
document.getElementById("battery_level").style.width = level + "%";
document.getElementById("battery_level").classList.remove('high');
document.getElementById("battery_level").classList.remove('medium');
document.getElementById("battery_level").classList.remove('low');
if (level > 66) document.getElementById("battery_level").classList.add('high');
else if (level >= 33) document.getElementById("battery_level").classList.add('medium');
else document.getElementById("battery_level").classList.add('low');
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment