100-project-100-days-website/100_projects/14-get-battery-level-&-toggle-light-dark-mode/app.js
2023-03-07 17:28:48 +03:00
Ask

21 lines
709 B
JavaScript

{fbd4fbe2df7aedce14d9ead0b2152bace80dae8a true 709 app.js 0xc002bb6770}

let sec = document.querySelector('.sec');
let toggle = document.querySelector('.toggle');
toggle.onclick = function() {
sec.classList.toggle('dark');
}
var percentage = document.querySelector('.percentage');
var percent = document.querySelector('.percent');
navigator.getBattery().then((battery) => {
percentage.style.width = battery.level * 100 + '%';
percent.innerHTML = battery.level * 100 + '%';
})
// var percentage = document.querySelector('.percentage');
// var percent = document.querySelector('.percent');
// navigator.getBattery().then(function(battery){
// percentage.style.width = battery.level * 100 + '%';
// percent.innerHTML = battery.level * 100 + '%';
// })