I developed an example, just below, that basically does what I said in the comments of your doubt. I created a Istener of the scroll event which checks on ranges, which are the offsetTop of sections
page, to find out on which section
the function scrollTo should position the scroll
.
// Object usado para regra
var oScroll = {
y: 0,
sec1: document.getElementById('sec1').offsetTop,
sec2: document.getElementById('sec2').offsetTop,
sec3: document.getElementById('sec3').offsetTop,
prevent: true
}
window.addEventListener('scroll', function(e) {
if(this.scrollY < oScroll.y) {
// subindo
if(this.scrollY > oScroll.sec1 && this.scrollY < oScroll.sec2) {
this.scrollTo(0, oScroll.sec1);
} else if(this.scrollY > oScroll.sec2 && this.scrollY < oScroll.sec3) {
this.scrollTo(0, oScroll.sec2);
} else if(this.scrollY > oScroll.sec3) {
this.scrollTo(0, oScroll.sec3);
}
} else if(this.scrollY > oScroll.y) {
// descendo
if(this.scrollY > oScroll.sec1 && this.scrollY < oScroll.sec2 && oScroll.prevent) {
this.scrollTo(0, oScroll.sec2);
} else if(this.scrollY > oScroll.sec2 && this.scrollY < oScroll.sec3) {
this.scrollTo(0, oScroll.sec3);
}
}
oScroll.y = this.scrollY;
});
body::-webkit-scrollbar {
display: none;
}
.main {
height: 1500px;
margin: 100px 0;
}
.section {
background: lightblue;
height: 500px;
margin: 10px 0;
}
<div class="main">
<div class="section" id="sec1">
<h1>
Section 1
</h1>
</div>
<div class="section" id="sec2">
<h1>
Section 2
</h1>
</div>
<div class="section" id="sec3">
<h1>
Section 3
</h1>
</div>
</div>
See the example on Jsfiddle if you prefer.
It wasn’t clear to me what you want. You can make an image?
– DH.
So instead of the user scrolling the page gradually as is normal,
– Afonso Jorge
@Afonsojorge Using a function that detects the "scrolling" action you can check if the height is in a range and this has a certain point on the page to which will be set the
scroll
.– Lucas Fontes Gaspareto
<br> http://alvarotrigo.com/fullPage/<br> You can try using this plugin! <br>Would that be it? <br> Remembering that your site will have to adapt in smaller resolutions
– concas