File size: 1,134 Bytes
ec87762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class CustomScrollProgress extends HTMLElement {
  connectedCallback() {
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        :host {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 3px;
            z-index: 9999;
            pointer-events: none;
        }

        .progress-bar {
            height: 100%;
            background: linear-gradient(90deg, #EAB308, #CA8A04);
            width: 0%;
            transition: width 0.1s ease-out;
            box-shadow: 0 0 10px rgba(234, 179, 8, 0.5);
        }
      </style>
      <div class="progress-bar" id="progress-bar"></div>
    `;

    const progressBar = this.shadowRoot.getElementById('progress-bar');
    
    window.addEventListener('scroll', () => {
      const scrollTop = window.scrollY;
      const docHeight = document.documentElement.scrollHeight - window.innerHeight;
      const progress = (scrollTop / docHeight) * 100;
      progressBar.style.width = `${progress}%`;
    });
  }
}
customElements.define('custom-scroll-progress', CustomScrollProgress);