mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
27 lines
760 B
JavaScript
27 lines
760 B
JavaScript
|
import {Controller} from "@hotwired/stimulus";
|
||
|
import {Tooltip} from "bootstrap";
|
||
|
|
||
|
export default class extends Controller {
|
||
|
|
||
|
connect() {
|
||
|
window.addEventListener('scroll', this._onscroll.bind(this));
|
||
|
}
|
||
|
|
||
|
_onscroll() {
|
||
|
const button = this.element;
|
||
|
|
||
|
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
|
||
|
button.style.display = "block";
|
||
|
} else {
|
||
|
button.style.display = "none";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
backToTop() {
|
||
|
//Hide button tooltip to prevent ugly tooltip on scroll
|
||
|
Tooltip.getInstance(this.element)?.hide();
|
||
|
|
||
|
document.body.scrollTop = 0; // For Safari
|
||
|
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
||
|
}
|
||
|
}
|