문제

<script>
function onbattery() {
window.addEventListener("batterystatus", onBatteryStatus, false);
document.getElementById('log1').innerHTML+="clicked";       
}

function onBatteryStatus(info) {

document.getElementById('log2').innerHTML+="get";
document.getElementById('getbatstatus').innerHTML+="Level: " + info.level + " isPlugged: "     + info.isPlugged;
}
</script>

<p id="log1">will display log1</p>
<p id="log2">will display log2</p>
<p id="getbatstatus">will display battery status</p>

Above code will display current battery status. On 1st click it showing very fast. But when i want to run it again..it will execute very slowly... why is this happen?

도움이 되었습니까?

해결책

The reason why is the batterystatus event only occurs when the battery status changes (power level increases, decreases or you plug your device in)

The first time you call onbattery, it gives the current status but then it waits for the system to raise the batterystatus event (could be a few minutes before change if you have a string battery)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top