JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<div id="s1">
Секция 1
</div>
<div id="s2">
Секция 2
</div>
<div id="s3">
Секция 3
</div>
<div id="s4">
Секция 4
</div>
<div id="s5">
Секция 5
</div>
<div id="s6">
Секция 6
</div>
CSS
body {
margin: 0;
padding: 0;
}
div {
width: 100%;
height: 300px;
padding-top: 10px;
padding-left: 20px;
box-sizing: border-box;
color: #ffffff;
}
#s1 {
background-color: #ff8080;
height: 100vh;
}
#s2 {
background-color: orange;
height: 100vh;
}
#s3 {
background-color: yellow;
height: 100vh;
}
#s4 {
background-color: yellowgreen;
height: 100vh;
}
#s5 {
background-color: lightgreen;
height: 100vh;
}
#s6 {
background-color: red;
}
a {
display: block;
margin-top: 50px;
}
JavaScript
var currentAnchor = 0;
var isAnimating = false;
function scrollUpDown(dir) {
var sections = $('#s1, #s2, #s3, #s4, #s5, #s6');
var currentScroll = $(document).scrollTop();
var nearestEl = null;
var defaultTop = 0;
sections.each(function(i, el) {
var el = $(el);
if (dir == 'down') {
if (currentScroll < el.offset().top) {
if (nearestEl != null && nearestEl.offset().top > el.offset().top) {
nearestEl = el;
} else if (nearestEl == null) {
nearestEl = el;
}
}
defaultTop = $(document).outerHeight(true);
}
if (dir == 'up') {
if (currentScroll > el.offset().top) {
if (nearestEl != null && nearestEl.offset().top < el.offset().top) {
nearestEl = el;
} else if (nearestEl == null) {
nearestEl = el;
}
}
var defaultTop = 0;
}
});
if (nearestEl != null) {
return(nearestEl.offset().top);
} else {
return(defaultTop);
}
}
$(function(){
$('body').on('wheel', function(e){
e.preventDefault();
e.stopPropagation();
if( isAnimating ) {
return false;
}
isAnimating = true;
// Increase or reset current anchor
if( e.originalEvent.deltaY < 0 ) {
currentAnchor = scrollUpDown('up');
} else{
...