Scroll-Snap: Unterschied zwischen den Versionen
Aus Wikizone
(Die Seite wurde neu angelegt: „ https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Scroll_Snap/Basic_concepts == Scroll Snap Basics == Die wichtigsten Eigenschaften sind scroll-snap-type…“) |
|||
| Zeile 6: | Zeile 6: | ||
scroll-snap-align (Kindelement) | scroll-snap-align (Kindelement) | ||
Die Eigenschaft scoll-snap-type wird auf das Elternelement angewendet und scroll-snap-align auf das Kindelement. | Die Eigenschaft scoll-snap-type wird auf das Elternelement angewendet und scroll-snap-align auf das Kindelement. | ||
| + | |||
| + | <pre> | ||
| + | /* Keyword values */ | ||
| + | scroll-snap-type: none; | ||
| + | scroll-snap-type: x; | ||
| + | scroll-snap-type: y; | ||
| + | scroll-snap-type: block; | ||
| + | scroll-snap-type: inline; | ||
| + | scroll-snap-type: both; | ||
| + | |||
| + | /* Optional mandatory | proximity*/ | ||
| + | scroll-snap-type: x mandatory; | ||
| + | scroll-snap-type: y proximity; | ||
| + | scroll-snap-type: both mandatory; | ||
| + | |||
| + | /* etc */ | ||
| + | |||
| + | /* Global values */ | ||
| + | scroll-snap-type: inherit; | ||
| + | scroll-snap-type: initial; | ||
| + | scroll-snap-type: unset; | ||
| + | </pre> | ||
Beispiel | Beispiel | ||
| + | |||
| + | Beispiel 2 | ||
<syntaxhighlight lang="html5"> | <syntaxhighlight lang="html5"> | ||
<article class="scroller"> | <article class="scroller"> | ||
| Zeile 25: | Zeile 49: | ||
<syntaxhighlight lang="css"> | <syntaxhighlight lang="css"> | ||
| − | + | <section><h2>SCROLL ME</h2><p>horizontal</p></section> | |
| − | + | <section><h2>SNAPPED</h2></section> | |
| − | + | <section><h2>GO ON</h2></section> | |
| − | + | <section><h2>THIS IS THE END</h2></section> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="css"> | <syntaxhighlight lang="css"> | ||
| − | body { | + | * { |
| + | box-sizing: border-box; | ||
| + | } | ||
| + | body,html{ | ||
| + | text-align: center; | ||
| + | min-height: 100%; | ||
margin: 0; | margin: 0; | ||
| − | scroll-snap-type: | + | padding: 0; |
| + | color: white; | ||
| + | font-family: sans-serif; | ||
| + | } | ||
| + | html { | ||
| + | margin: 0; | ||
| + | scroll-snap-type: x mandatory; | ||
| + | } | ||
| + | body{ | ||
| + | /* | ||
| + | NOT working | ||
| + | scroll-snap-type: y mandatory; | ||
| + | */ | ||
| + | display:flex; | ||
| + | } | ||
| + | h2{ | ||
| + | text-align: center; | ||
} | } | ||
| − | |||
section { | section { | ||
| + | display: flex; | ||
| + | flex-direction: column; | ||
| + | justify-content: center; | ||
height: 100vh; | height: 100vh; | ||
| − | scroll-snap-align: start; /* | + | width: 100%; |
| + | flex-shrink: 0; | ||
| + | scroll-snap-align: start; /* Stop at the left */ | ||
| + | |||
| + | background: #146585; | ||
} | } | ||
section:nth-of-type(even) { | section:nth-of-type(even) { | ||
| − | background: # | + | background: #2b8664; |
} | } | ||
| + | </syntaxhighlight> | ||
| − | + | == scroll-padding und scroll-margin == | |
| − | + | Hiermit lassen sich die Scrollpunkte justieren, wenn man z.B. einen fest positionierten Header hat, oder mit Abständen zwischen den Elementen hat. | |
| − | + | scroll-padding-topscroll-margin-top | |
| − | |||
Version vom 23. März 2020, 17:55 Uhr
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Scroll_Snap/Basic_concepts
Scroll Snap Basics
Die wichtigsten Eigenschaften sind
scroll-snap-type (Containerelement) scroll-snap-align (Kindelement)
Die Eigenschaft scoll-snap-type wird auf das Elternelement angewendet und scroll-snap-align auf das Kindelement.
/* Keyword values */ scroll-snap-type: none; scroll-snap-type: x; scroll-snap-type: y; scroll-snap-type: block; scroll-snap-type: inline; scroll-snap-type: both; /* Optional mandatory | proximity*/ scroll-snap-type: x mandatory; scroll-snap-type: y proximity; scroll-snap-type: both mandatory; /* etc */ /* Global values */ scroll-snap-type: inherit; scroll-snap-type: initial; scroll-snap-type: unset;
Beispiel
Beispiel 2
<article class="scroller">
<section>
<h2>Section one</h2>
</section>
<section>
<h2>Section two</h2>
</section>
<section>
<h2>Section three</h2>
</section>
</article>
<section><h2>SCROLL ME</h2><p>horizontal</p></section>
<section><h2>SNAPPED</h2></section>
<section><h2>GO ON</h2></section>
<section><h2>THIS IS THE END</h2></section>
* {
box-sizing: border-box;
}
body,html{
text-align: center;
min-height: 100%;
margin: 0;
padding: 0;
color: white;
font-family: sans-serif;
}
html {
margin: 0;
scroll-snap-type: x mandatory;
}
body{
/*
NOT working
scroll-snap-type: y mandatory;
*/
display:flex;
}
h2{
text-align: center;
}
section {
display: flex;
flex-direction: column;
justify-content: center;
height: 100vh;
width: 100%;
flex-shrink: 0;
scroll-snap-align: start; /* Stop at the left */
background: #146585;
}
section:nth-of-type(even) {
background: #2b8664;
}
scroll-padding und scroll-margin
Hiermit lassen sich die Scrollpunkte justieren, wenn man z.B. einen fest positionierten Header hat, oder mit Abständen zwischen den Elementen hat. scroll-padding-topscroll-margin-top