Skip to content
Snippets Groups Projects

Improve scroll to top behaviour

Merged Tögl, Christina requested to merge app-shell-scroll-to-activity-top-improvement into master
1 file
+ 22
3
Compare changes
  • Side-by-side
  • Inline
@@ -348,6 +348,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
@@ -348,6 +348,7 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
}
}
switchComponent(componentTag) {
switchComponent(componentTag) {
 
let offset = window.pageYOffset;
const changed = (componentTag !== this.activeView);
const changed = (componentTag !== this.activeView);
this.activeView = componentTag;
this.activeView = componentTag;
if (changed)
if (changed)
@@ -359,8 +360,27 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
@@ -359,8 +360,27 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
}
}
let updateFunc = () => {
let updateFunc = () => {
if (window.pageYOffset !== 0) {
window.scrollTo(0, 96);
if (offset > 0) {
 
 
const header = this.shadowRoot.querySelector("header");
 
const title = this.shadowRoot.querySelector("#headline");
 
 
if (header === null || title === null) {
 
return;
 
}
 
 
let style = getComputedStyle(title);
 
let marginTop = isNaN(parseInt(style.marginTop, 10)) ? 0 : parseInt(style.marginTop, 10);
 
let marginBottom = isNaN(parseInt(style.marginBottom, 10)) ? 0 : parseInt(style.marginBottom, 10);
 
 
let topValue = header.getBoundingClientRect().height + title.getBoundingClientRect().height + marginTop + marginBottom;
 
 
if (offset < topValue) {
 
window.scrollTo(0, offset);
 
} else {
 
window.scrollTo(0, topValue);
 
}
}
}
this.updatePageTitle();
this.updatePageTitle();
this.subtitle = this.activeMetaDataText("short_name");
this.subtitle = this.activeMetaDataText("short_name");
@@ -811,7 +831,6 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
@@ -811,7 +831,6 @@ export class AppShell extends ScopedElementsMixin(AdapterLitElement) {
<dbp-tugraz-logo id="main-logo" lang="${this.lang}" class="${classMap({hidden: this.noBrand})}"></dbp-tugraz-logo>
<dbp-tugraz-logo id="main-logo" lang="${this.lang}" class="${classMap({hidden: this.noBrand})}"></dbp-tugraz-logo>
</div>
</div>
</header>
</header>
<div id="headline">
<div id="headline">
<h1 class="title">${this.topicMetaDataText('name')}</h1>
<h1 class="title">${this.topicMetaDataText('name')}</h1>
</div>
</div>
Loading