Battery API

Developer
Size
3,321 Kb
Views
4,048

How do I make an battery api?

A battery using the values from the battery API.Bolt stolen from: http://codepen.io/lindsaylee/pen/pFqBg. What is a battery api? How do you make a battery api? This script and codes were developed by Daryll Doyle on 24 January 2023, Tuesday.

Battery API Previews

Battery API - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Battery API</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <h1>Battery API Battery</h1>
<p class="level" id="JSLevel"></p>
<div class="battery" id="JSBattery"> <div class="bolt"></div> <div class="inner" id="JSInner"></div>
</div>
<div class="error" id="JSError"></div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Battery API - Script Codes CSS Codes

.battery { width: 20em; height: 5.71429em; border: 0.5em solid #000; position: relative; top: calc(20vh - (5.71429em / 2)); left: calc(50vw - (20em / 2)); box-sizing: border-box; border-radius: .5em;
}
.battery::after { content: ''; display: block; position: relative; left: 100%; top: calc(-50% - (2.28571em / 2)); width: 1.33333em; height: 2.28571em; background: #000; border-radius: 0 .3em .3em 0;
}
.battery .inner { height: 100%; width: 0; background: -webkit-linear-gradient(#33ff33, #090); background: linear-gradient(#33ff33, #090); border: 0.2em solid #fff; box-sizing: border-box; -webkit-transition: width 2s ease; transition: width 2s ease;
}
.bolt { position: absolute; top: -25%; left: 45%; -webkit-transform: rotate(50deg); transform: rotate(50deg); display: none;
}
.charging .bolt { display: block;
}
.bolt::before { content: ''; display: block; position: relative; width: 0; height: 0; border-bottom: 3.80952em solid #e98300; border-left: 1.33333em solid transparent; transform: rotate(0deg) skew(-5deg, -10deg); -ms-transform: rotate(0deg) skew(-5deg, -10deg); -webkit-transform: rotate(0deg) skew(-5deg, -10deg); top: 0; left: 0;
}
.bolt::after { content: ''; display: block; position: relative; width: 0; height: 0; border-bottom: 3.80952em solid #e98300; border-left: 1.33333em solid transparent; transform: rotate(180deg) skew(-5deg, -10deg); -ms-transform: rotate(180deg) skew(-5deg, -10deg); -webkit-transform: rotate(180deg) skew(-5deg, -10deg); top: -20px; left: 10px;
}
/* PEN CSS */
h1,
p { width: 100%; text-align: center; padding: 0 2em; box-sizing: border-box;
}

Battery API - Script Codes JS Codes

var battery;
function batterySuccess(batteryManager) { battery = batteryManager; //document.getElementById("promiseStatus").innerHTML = "success"; updateBatteryInformation(); battery.addEventListener('chargingchange', function() { updateBatteryInformation(); }); battery.addEventListener('levelchange', function() { updateBatteryInformation(); });
}
function batteryFailure() { document.getElementById("JSError").innerHTML = "Your browser doesn't support the battery API";
}
function updateBatteryInformation() { if(battery.charging === true) { $('#JSBattery').addClass('charging'); } else { $('#JSBattery').removeClass('charging'); } var level = (battery.level * 100); document.getElementById("JSInner").style.width = level + '%'; document.getElementById("JSLevel").innerHTML = level + '%';
}
if(typeof navigator.getBattery() == 'object') { navigator.getBattery().then(batterySuccess, batteryFailure);
} else { batterySuccess(window.navigator.battery);
}
Battery API - Script Codes
Battery API - Script Codes
Home Page Home
Developer Daryll Doyle
Username darylldoyle
Uploaded January 24, 2023
Rating 3
Size 3,321 Kb
Views 4,048
Do you need developer help for Battery API?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Daryll Doyle (darylldoyle) Script Codes
Create amazing love letters with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!