Basic Parallax Effect
by davidxmartins
HTML
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="rendom-content"><h1>SCROLL DOWN</h1></div>
<div class="parallax"></div>
<div class="rendom-content"><h1>SCROLL UP</h1></div>
</body>
</html>
CSS
html, body {
width: 100%;
height: 100%;
margin: 0;
padding; 0;
}
.rendom-content {
height: 100vh;
background: #aaa;
color: white;
font-family: sans-serif;
font-size: 3vw;
display: flex;
align-items: center;
justify-content: center;"
}
/* PARALAX DIV */
.parallax {
background-image: url("https://picsum.photos/1500/2000?grayscale");
/* Set a specific height */
min-height: 300px;
/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}