I want to achieve the same effect at http://www.squaredot.eu/#Intro
So if I scroll down, the body must scroll 100vh to the bottom. And also if scroll up, the body must scroll 100vh up. I tried something, but it didn't work out.
HTML:
<!DOCTYPE html>
<html>
<head>
<title> Log In </title>
<link href="main.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="e1"></div>
<div id="e2"></div>
<div id="e3"></div>
<div id="e4"></div>
<div id="e5"></div>
</body>
</html>
CSS:
body, html {
height: 100%;
margin: 0;
padding: 0;
}
#e1 {
width: 100%;
height: 100vh;
background-color: red;
}
#e2 {
width: 100%;
height: 100vh;
background-color: green;
}
#e3 {
width: 100%;
height: 100vh;
background-color: yellow;
}
#e4 {
width: 100%;
height: 100vh;
background-color: blue;
}
#e5 {
width: 100%;
height: 100vh;
background-color: orange;
}
JAVASCRIPT
document.addEventListener('scroll', function(e) {
var currScroll = document.body.scrollTop;
document.body.scrollTop = calc(~"currScroll + 100vh");
}
);
One solution could be using transform from CSS (like the website you linked is doing).
Add this as css:
And this as javascript
It only works for element 1 and 2 but it's a start, and you can learn how to implement the other steps!
Working example here: https://jsbin.com/titaremevi/edit?css,js,output
UPDATE:
This is the fully working solution:
You can see it working here: https://jsbin.com/foxigobano/1/edit?js,output
What I would do is cancel the default scroll behaviour and, then, use wheel to simulate it.
The main challenge here is to transform vh to px. I have used one of the elements with set vh for the conversion. It ends up being useless, but it is prepared in case you want to change the size of the scroll.
Working version:
Now, while this is what you asked, I feel this is not what you really want. I understand that you want to scroll to the next div. For that, I would reuse that logic and register to what #eX I scrolled last time and use document.querySelector('#eX').scrollTop to set up the scroll of the body. That'd solve, for example, the issue of having 1-5 pixels from the previous box when scrolling.
As you have already realised about this issue on the comments, adding the new solution: