Wenn Sie einen Fragmentbezeichner suchen.
Fügen Sie dem Abschnitt, zu dem Sie blättern möchten, ein id
-Attribut hinzu.
Beispiel: <section id="shop"> ... </section>
Dann einen Anker verwendet <a>
anstelle einer Schaltfläche mit einem href
Attribute.
Beispiel: <a href="#shop">Shop</a>
Einfaches Beispiel:
#shop {
margin-top: 300vh;
background-color: tomato;
height: 100vh;
position: relative;
}
#shop::after {
content: 'Shop Content';
position: absolute;
color: white;
font-size: 3em;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
<a href="#shop">Shop</a>
<section id="shop"></section>
Wenn glatte Scroll gesucht, kann scrollIntoView
wie so verwendet werden:
document.querySelector('#shopBtn').addEventListener('click', function() {
document.querySelector('#shop').scrollIntoView({
behavior: 'smooth'
});
});
#shop {
margin-top: 300vh;
background-color: tomato;
height: 100vh;
position: relative;
}
#shop::after {
content: 'Shop Content';
position: absolute;
color: white;
font-size: 3em;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
justify-content: center;
align-items: center;
}
<button id="shopBtn">Shop</button>
<section id="shop"></section>
https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView –