class BackToTop extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ` `; const button = this.shadowRoot.querySelector('button'); button.addEventListener('click', () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }); window.addEventListener('scroll', this.handleScroll.bind(this)); feather.replace(); } handleScroll() { if (window.scrollY > 300) { this.classList.add('visible'); } else { this.classList.remove('visible'); } } } customElements.define('back-to-top', BackToTop);