Prozess Balken mit Counter Prozent und farblichen Wechsel des Balkens
Code
<!doctype html>
<html lang="de">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style>
body {
display: flex;
flex-direction: column;
height: 100vh;
align-items: center;
justify-content: flex-start;
}
#helper{
border:1px solid black;
height:30px;
width:300px;
overflow:hidden;
}
#conti{
position:relative;
top:0px;
left:0px;
height:30px;
width:10300px;
background:linear-gradient(
to right,
red 25%, orange 50%, yellow 70%,green 100%);
}
#aus{
position:absolute;
margin-left:130px;
font-size:25px;
font-weight:900;
}
#contibalken{
width:300px;
height:200px;
border:2px solid black;
text-align:center;
}
#contibalken p{
text-align:center;
font-weight:900;
font-size:25px;
}
#sekundenbalken{
width:200px;
height:25px;
border:2px solid black;
border-radius:10px;
text-align:center;
font-size:20px;
font-weight:900;
margin-top:10px;
}
#sekundenbalken:hover{
border:2px solid green;
}
#time,.blinkno{
font-size:30px;
color:black;
}
.blink{
animation:blinki linear forwards 1s infinite;
}
@keyframes blinki{
0%,49%,100%{
color:white;
}50%{
color:red;
}
}
</style>
</head>
<body>
<div id="oben">
<h3>Beschreibung</h3>
<ul>
<li>Eingabe von Sekunden.</li>
<li>Uhr läuft rückwärts.</li>
<li>Die letzten 10 Sekunden blinkt die Zeit.</li>
<li>Einfacher Neustart durch Oninput Event.</li>
<li>Restzeit wird nach Eingabe sofort angezeigt<br>auch wenn wärend des laufens eine neue Zeit eingegeben wird.</li>
<li>Mfg Basti1012</li>
</div>
<div id="contibalken">
<p>Prozess Balken</p>
<input type="number" id="sekundenbalken" value="" min="1" max="3600" step="1" value="10" placeholder="Sekunden...">
<div id="time"></div>
<div id="helper">
<div id="conti">
<div id="aus">0 %</div>
</div>
</div>
</div>
<script>
function los(a,sek){
sekunden=sek;
var l=1000/sekunden;
if(a<=10000){
$('#conti').css('left','-'+a+'px');
a=a+l;
timer=setTimeout(function(){
los(a,sek)
},100)
a1=a/100;
a1=a1.toFixed(3);
$('#aus').html(a1+' %')
a1=a-l;
$('#aus').css('left',''+a1+'px');
}else{}
}
$('#sekundenbalken').on('input',function(){
try{
clearTimeout(timer1);
clearTimeout(timer);
}catch(e){
}
los(1,this.value)
uhr(this.value);
});
function uhr(timeleft){
hour = Math.floor( timeleft / 3600 );
minute = Math.floor( (timeleft%3600) / 60 );
second = Math.floor( timeleft%60 );
if(hour<=9){
hour='0'+hour
}
if(minute<=9){
minute='0'+minute
}
if(second<=9){
second='0'+second
}
$('#time').html('Restzeit <br> '+hour+'-'+minute+'-'+second);
if(timeleft<=0){
}else{
timer1=setTimeout(function(){uhr(timeleft-1)},1000);
}
if(timeleft>=1 && timeleft<=10){
$('#time').addClass('blink');
}else{
bli= $('#time').hasClass('blink');
if(bli==true){
$('#time').removeClass('blink');
$('#time').hasClass('blinkno');
}
}
}
</script>
</body>
</html>