feat(ui): Back-to-top Button (sichtbar nach Scroll, smooth scroll nach oben)
This commit is contained in:
parent
b70703d51b
commit
f920aae969
2 changed files with 35 additions and 0 deletions
|
|
@ -15,6 +15,7 @@ export default function App() {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [info, setInfo] = useState<string | null>(null);
|
const [info, setInfo] = useState<string | null>(null);
|
||||||
|
const [showTop, setShowTop] = useState<boolean>(false);
|
||||||
const [volume, setVolume] = useState<number>(1);
|
const [volume, setVolume] = useState<number>(1);
|
||||||
const [favs, setFavs] = useState<Record<string, boolean>>({});
|
const [favs, setFavs] = useState<Record<string, boolean>>({});
|
||||||
const [theme, setTheme] = useState<string>(() => localStorage.getItem('theme') || 'dark');
|
const [theme, setTheme] = useState<string>(() => localStorage.getItem('theme') || 'dark');
|
||||||
|
|
@ -85,6 +86,14 @@ export default function App() {
|
||||||
localStorage.setItem('theme', theme);
|
localStorage.setItem('theme', theme);
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
|
// Back-to-top Sichtbarkeit
|
||||||
|
useEffect(() => {
|
||||||
|
const onScroll = () => setShowTop(window.scrollY > 300);
|
||||||
|
onScroll();
|
||||||
|
window.addEventListener('scroll', onScroll, { passive: true });
|
||||||
|
return () => window.removeEventListener('scroll', onScroll);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
if (selected) {
|
if (selected) {
|
||||||
|
|
@ -328,6 +337,16 @@ export default function App() {
|
||||||
</section>
|
</section>
|
||||||
{/* footer counter entfällt, da oben sichtbar */}
|
{/* footer counter entfällt, da oben sichtbar */}
|
||||||
</div>
|
</div>
|
||||||
|
{showTop && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="back-to-top"
|
||||||
|
aria-label="Nach oben"
|
||||||
|
onClick={() => window.scrollTo({ top: 0, behavior: 'smooth' })}
|
||||||
|
>
|
||||||
|
↑ Top
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -225,5 +225,21 @@ header p { opacity: .8; }
|
||||||
.tab.active { background: linear-gradient(135deg, rgba(168,85,247,.55), rgba(59,130,246,.55)); color: #fff; border-color: transparent; }
|
.tab.active { background: linear-gradient(135deg, rgba(168,85,247,.55), rgba(59,130,246,.55)); color: #fff; border-color: transparent; }
|
||||||
|
|
||||||
|
|
||||||
|
/* Back to top */
|
||||||
|
.back-to-top {
|
||||||
|
position: fixed;
|
||||||
|
right: 24px;
|
||||||
|
bottom: 24px;
|
||||||
|
padding: 10px 14px;
|
||||||
|
border-radius: 999px;
|
||||||
|
border: 1px solid rgba(255,255,255,.25);
|
||||||
|
background: linear-gradient(180deg, rgba(255,255,255,.14), rgba(255,255,255,.06));
|
||||||
|
color: #e7e7ee;
|
||||||
|
box-shadow: 0 10px 30px rgba(0,0,0,.35);
|
||||||
|
z-index: 40000;
|
||||||
|
}
|
||||||
|
.back-to-top:hover { filter: brightness(1.1); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue