diff --git a/assets/controllers/scroll_indicator_controller.js b/assets/controllers/scroll_indicator_controller.js new file mode 100644 index 000000000..1fab9b4ed --- /dev/null +++ b/assets/controllers/scroll_indicator_controller.js @@ -0,0 +1,10 @@ +import { Controller } from '@hotwired/stimulus'; + +export default class extends Controller { + updateWidth() { + const referenceHeight = document.body.offsetHeight - window.innerHeight; + const scrollPercent = (window.scrollY / referenceHeight) * 100; + + this.element.style.width = `${scrollPercent}%`; + } +} diff --git a/assets/index.js b/assets/index.js index 99234c625..2bc2e517f 100755 --- a/assets/index.js +++ b/assets/index.js @@ -242,22 +242,8 @@ const stickyNav = () => { }); }; -const articleScroll = () => { - const articleEl = $('#article'); - if (articleEl.length > 0) { - $(window).scroll(() => { - const s = $(window).scrollTop(); - const d = $(document).height(); - const c = $(window).height(); - const scrollPercent = (s / (d - c)) * 100; - $('.progress .determinate').css('width', `${scrollPercent}%`); - }); - } -}; - $(document).ready(() => { stickyNav(); - articleScroll(); initPreviewText(); const toggleNav = (toShow, toFocus) => { diff --git a/templates/Entry/entry.html.twig b/templates/Entry/entry.html.twig index 70705d429..a2d184c57 100644 --- a/templates/Entry/entry.html.twig +++ b/templates/Entry/entry.html.twig @@ -8,7 +8,7 @@ {% block menu %}