Ich versuche, Fortschrittsbalken für meine Ein-Seiten-Website und alles funktioniert und wie ich mit Ausnahme machen will, wenn Seite ist bar Last läuft auf 100% nicht auf 0% bis ich blättern beginnen. Dies ist mein Code:Progress Bar 100% auf Last
HTML
<div class="progressContainer">
<div id="progress" class="progress"></div>
</div>
CSS
.progressContainer{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 10px;
background-color: rgba(0,0,0,0.65);
}
.progress{
height: 10px;
background: #D66A00;
border-radius: 0;
}
JavaScript
function updateProgress(num1, num2){
var percent = Math.ceil(num1/num2 * 100) + '%';
document.getElementById('progress').style.width = percent;
}
window.addEventListener('scroll', function(){
var top = window.scrollY;
var height = document.body.getBoundingClientRect().height - window.innerHeight;
updateProgress(top, height);
});
DEMO
https://codepen.io/Klak031/pen/xdXYgb/
Nun, es ist nur, dass .progress Element erbt die Breite von Eltern, so dass es 100% beim Start, ändern Sie es in 0 in der css-Deklaration –
.progress {width: 0%;} nur hinzufügen, um Ihre CSS –
Das funktioniert: Danke) – Klak031