The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Full page parallax scroll effect</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<div class="background">
<div class="content">
<h2>First Section</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Dolorum pariatur quod beatae in! Mollitia
quisquam quod doloremque voluptates. Voluptatum velit modi rerum necessitatibus, dicta delectus
nesciunt deleniti doloremque iure dolores?</p>
</div>
</div>
<div class="background">
<div class="content">
<h2>Second Section</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Unde error culpa voluptate commodi
accusantium a earum corporis veniam tempora odio fuga voluptas in fugiat nihil, facere eos iusto!
Pariatur, quisquam.</p>
</div>
</div>
<div class="background">
<div class="content">
<h2>Third Section</h2>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tempore doloribus repellendus, dignissimos
quasi, atque recusandae dolorem ipsa consectetur temporibus, facere illo nulla quam dolores fuga
velit molestiae similique error expedita.</p>
</div>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
Below is the css code for this video.
style.css
@import url('https://fonts.googleapis.com/css2?family=PT+Mono&display=swap');
* {
margin: 0;
padding: 0;
}
body {
height: 100vh;
width: 100%;
overflow: hidden;
}
.background {
position: fixed;
transform: translateY(30vh);
height: 130vh;
width: 100%;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
backface-visibility: hidden;
will-change: transform;
overflow: hidden;
transition: all 1.25s cubic-bezier(0.22, 0.44, 0, 1);
}
.background::before {
content: "";
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
height: 100%;
width: 100%;
background-color: #00000040;
}
.background:first-child {
background-image: url(https://images.unsplash.com/photo-1523510468197-455cc987be86?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80);
transform: translateY(-15vh);
z-index: 3;
}
.background:first-child .content {
transform: translateY(15vh);
}
.background:nth-child(2) {
background-image: url(https://images.unsplash.com/photo-1504253492562-cbc4dc540fcb?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80);
z-index: 2;
}
.background:nth-child(3) {
background-image: url(https://images.unsplash.com/photo-1461696114087-397271a7aedc?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1470&q=80);
z-index: 1;
}
.content {
display: flex;
height: 100vh;
color: #ffffff;
font-family: 'PT Mono', monospace;
justify-content: center;
text-align: center;
flex-flow: column nowrap;
transform: translateY(40vh);
will-change: transform;
backface-visibility: hidden;
transition: all 1.75s cubic-bezier(0.22, 0.44, 0, 1);
}
h2 {
width: 91%;
font-size: 82px;
text-transform: uppercase;
line-height: 2;
margin: 0 auto;
}
p {
width: 82%;
font-size: 19px;
line-height: 1.5;
margin: 0 auto;
}
.background.scroll-up {
transform: translate3d(0, -15vh, 0);
}
.background.scroll-up .content {
transform: translateY(15vh);
}
.background.scroll-up+.background {
transform: translate3d(0, 30vh, 0);
}
.background.scroll-up+.background .content {
transform: translateY(30vh);
}
.background.scroll-down {
transform: translate3d(0, -130vh, 0);
}
.background.scroll-down .content {
transform: translateY(40vh);
}
.background.scroll-down+.background:not(.scroll-down) {
transform: translate3d(0, -15vh, 0);
}
.background.scroll-down+.background:not(.scroll-down) .content {
transform: translateY(15vh);
}
Below is the javascript code for this video.
index.js
var ticking = false, scrollSensitivity = 30, currentSlideNumber = 0;
const slideDuration = 600, mouseWheelEvent = "wheel";
var totalSlides = document.querySelectorAll(".background").length;
function parallaxScroll(event) {
var delta = event.wheelDelta;
if (!ticking) {
if (delta <= -scrollSensitivity) {
ticking = true;
if (currentSlideNumber !== totalSlides - 1) {
currentSlideNumber++;
nextSlide();
}
slideDurationTimeout(slideDuration);
}
if (delta >= scrollSensitivity) {
ticking = true;
if (currentSlideNumber !== 0) {
currentSlideNumber--;
previousSlide();
}
slideDurationTimeout(slideDuration);
}
}
}
function slideDurationTimeout(slideDuration) { setTimeout(function () { ticking = false; }, slideDuration); }
function nextSlide() {
var previousSlide = document.querySelectorAll(".background")[currentSlideNumber - 1];
previousSlide.classList.remove("scroll-up");
previousSlide.classList.add("scroll-down");
}
function previousSlide() {
var currentSlide = document.querySelectorAll(".background")[currentSlideNumber];
currentSlide.classList.remove("scroll-down");
currentSlide.classList.add("scroll-up");
}
window.addEventListener(mouseWheelEvent, function (event) { parallaxScroll(event); }, false);
Thanks for visiting