Created
June 17, 2020 02:11
-
-
Save DougBeney/310df0380144bc2f826969a1074bd349 to your computer and use it in GitHub Desktop.
Very Simple Snap Scrolling CSS Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"/> | |
<title>Snap Scrolling</title> | |
<meta name="viewport" content="width=device-width, initial-scale=1"/> | |
<style> | |
html, body { margin: 0; } | |
.scrolly { | |
display: flex; | |
width: 100vw; | |
height: 100vh; | |
scroll-snap-type: both mandatory; | |
overflow: auto; | |
/* y axis snap scrolling */ | |
flex-direction: column; | |
/* x axis snap scrolling */ | |
/* flex-direction: row; */ | |
} | |
section { | |
background: url("http://placekitten.com/1280/1080"); | |
background-size: cover; | |
background-position: top center; | |
width: 100%; | |
height: 100%; | |
scroll-snap-align: start; | |
flex-shrink: 0; | |
} | |
section.cat2 { background-image: url("http://placekitten.com/1280/1080?blah"); } | |
</style> | |
</head> | |
<body> | |
<div class="scrolly"> | |
<section></section> | |
<section class="cat2"></section> | |
<section></section> | |
<section class="cat2"></section> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment