mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-15 18:57:05 +00:00
Extract Scroll Indicator controller
This commit is contained in:
parent
503b82ea13
commit
019d252446
3 changed files with 11 additions and 15 deletions
10
assets/controllers/scroll_indicator_controller.js
Normal file
10
assets/controllers/scroll_indicator_controller.js
Normal file
|
@ -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}%`;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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(() => {
|
$(document).ready(() => {
|
||||||
stickyNav();
|
stickyNav();
|
||||||
articleScroll();
|
|
||||||
initPreviewText();
|
initPreviewText();
|
||||||
|
|
||||||
const toggleNav = (toShow, toFocus) => {
|
const toggleNav = (toShow, toFocus) => {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
{% block menu %}
|
{% block menu %}
|
||||||
<div class="progress">
|
<div class="progress">
|
||||||
<div class="determinate"></div>
|
<div class="determinate" data-controller="scroll-indicator" data-action="scroll@window->scroll-indicator#updateWidth"></div>
|
||||||
</div>
|
</div>
|
||||||
<nav class="hide-on-large-only js-entry-nav-top">
|
<nav class="hide-on-large-only js-entry-nav-top">
|
||||||
<div class="nav-panel-item cyan darken-1">
|
<div class="nav-panel-item cyan darken-1">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue