大家好!
我們今天要實作的自訂滾動卷軸,不僅能自訂方向、選擇更多樣式,甚至支援度比 CSS 更廣。
我們進入今天的主題吧!
(function () {
    const bar = Felix('body').insert('#scrollbar');
    bar.style = 'position: fixed; left: 0; right: 0; bottom: 0; z-index: 999; width: 0; height: 0.5em; background-color: rgb(250, 125, 125);';
    window.addEventListener('scroll', function () {
        const schedule = window.scrollY / (Felix('html')[0].clientHeight - window.innerHeight);
        bar.style.width = schedule * 100 + '%';
    });
})();
差不多也到尾聲了。
如果對文章有任何疑問,也歡迎在下方提問和建議!
我是 Felix,我們明天再見!