feat: scroll to top button
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { Component } from "@angular/core";
|
import { Component } from "@angular/core";
|
||||||
import { RouterModule } from '@angular/router';
|
import { RouterModule } from "@angular/router";
|
||||||
import { PanelComponent } from "./modules/panel/panel.component";
|
import { PanelComponent } from "./modules/panel/panel.component";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
margin-inline: 2rem;
|
margin-inline: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1, h2 {
|
||||||
color: #efdee0;
|
color: #efdee0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin: 1rem 2rem;
|
margin: 1rem 2rem;
|
||||||
|
|||||||
@@ -28,3 +28,6 @@
|
|||||||
<button id="close_win" (click)="onCloseClicked()"><i class="lni lni-close"></i></button>
|
<button id="close_win" (click)="onCloseClicked()"><i class="lni lni-close"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<app-text-list [elements]="elements"></app-text-list>
|
<app-text-list [elements]="elements"></app-text-list>
|
||||||
|
<nwui-button class="to-top-btn" (click)="scrollToTop()"
|
||||||
|
><i class="lni lni-arrow-up"></i
|
||||||
|
></nwui-button>
|
||||||
|
|||||||
@@ -45,3 +45,14 @@
|
|||||||
min-height: calc(100vh - 2rem);
|
min-height: calc(100vh - 2rem);
|
||||||
scrollbar-color: #413738;
|
scrollbar-color: #413738;
|
||||||
}
|
}
|
||||||
|
.to-top-btn {
|
||||||
|
position: fixed;
|
||||||
|
width: 2rem;
|
||||||
|
left: 2rem;
|
||||||
|
bottom: -5rem;
|
||||||
|
transition: bottom 0.3s ease-in-out;
|
||||||
|
|
||||||
|
&.active {
|
||||||
|
bottom: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { CommonModule } from "@angular/common";
|
import { CommonModule } from "@angular/common";
|
||||||
import { Component, OnInit, ViewChild } from "@angular/core";
|
import { AfterViewInit, Component, OnInit, ViewChild } from "@angular/core";
|
||||||
import { Router } from "@angular/router";
|
import { Router } from "@angular/router";
|
||||||
import { NWUIButtonComponent } from "@nwaifu-ui";
|
import { NWUIButtonComponent } from "@nwaifu-ui";
|
||||||
|
import { fromEvent, map } from "rxjs";
|
||||||
import { TextListComponent } from "./components/text_list/text_list.component";
|
import { TextListComponent } from "./components/text_list/text_list.component";
|
||||||
import { LocalStorageKeys } from "./consts";
|
import { LocalStorageKeys } from "./consts";
|
||||||
import { NpsFile, TranslateData } from "./dto/translate_data.dto";
|
import { NpsFile, TranslateData } from "./dto/translate_data.dto";
|
||||||
@@ -14,7 +15,7 @@ import { parse } from "./lib/parser";
|
|||||||
templateUrl: "./nitroplus-translator.component.html",
|
templateUrl: "./nitroplus-translator.component.html",
|
||||||
styleUrl: "./nitroplus-translator.component.less",
|
styleUrl: "./nitroplus-translator.component.less",
|
||||||
})
|
})
|
||||||
export class NitroplusComponent implements OnInit {
|
export class NitroplusComponent implements OnInit, AfterViewInit {
|
||||||
title = "NitroPlusTranslator";
|
title = "NitroPlusTranslator";
|
||||||
elements: TranslateData[] = [];
|
elements: TranslateData[] = [];
|
||||||
@ViewChild("fileInput") fileInput: HTMLInputElement | null = null;
|
@ViewChild("fileInput") fileInput: HTMLInputElement | null = null;
|
||||||
@@ -36,6 +37,25 @@ export class NitroplusComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewInit(): void {
|
||||||
|
const container = document.querySelector("main");
|
||||||
|
if (container) {
|
||||||
|
fromEvent(container, "scroll")
|
||||||
|
.pipe(map(() => container.scrollTop > 100))
|
||||||
|
.subscribe((val) => {
|
||||||
|
if (val) document.querySelector(".to-top-btn")?.classList.add("active");
|
||||||
|
else document.querySelector(".to-top-btn")?.classList.remove("active");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
scrollToTop() {
|
||||||
|
const container = document.querySelector("main");
|
||||||
|
if (container) {
|
||||||
|
container.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
submitFile($event: Event) {
|
submitFile($event: Event) {
|
||||||
const target = $event.target as HTMLInputElement;
|
const target = $event.target as HTMLInputElement;
|
||||||
if (target.files) {
|
if (target.files) {
|
||||||
|
|||||||
Reference in New Issue
Block a user