1st question: Can't figure out why .animate linear slows down when it comes to its destination point. What am I missing ?
Weird thing is that going from middle pic upward it always works perfectly (only in that one case).
2nd question: Is there a way to disable user from scrolling while animation is on-going ?
[edit] I have cut out pictures so it is easier to debug [/edit]
$(document).ready( function (){
var scrollCheck = 0;
var heightVal = window.innerHeight;
$(window).resize(function(){
window.scroll(0,0);
heightVal = window.innerHeight;
hControl1 = heightVal -1;
scrollCheck = 0;
});
var isScrolling = false;
window.addEventListener("scroll", throttleScroll, false);
function throttleScroll(e) {
if (isScrolling == false) {
window.requestAnimationFrame(function() {
scrolling(e);
isScrolling = false;
//console.log("Scrolling");
});
}
isScrolling = true;
}
document.addEventListener("DOMContentLoaded", scrolling, false);
function scrolling(e) {
var yValue = $(window).scrollTop();
//1st photo, scroll down
if ( yValue > 0 && scrollCheck === 0 ){
$('body').stop().animate({scrollTop:heightVal}, 700, 'linear');
if ( window.pageYOffset === heightVal ){
scrollCheck = 1;
//console.log(window.pageYOffset);
}
}//2nd photo, scroll up
else if( yValue < heightVal && scrollCheck === 1 ){
$('body').stop().animate({scrollTop:(-heightVal)}, 700, 'linear');
if ( window.pageYOffset === 0 ){
scrollCheck = 0;
}
}//2nd photo, scroll down
else if( yValue > heightVal && scrollCheck === 1 ){
$('body').stop().animate({scrollTop:(heightVal*2)}, 700, 'linear');
if ( window.pageYOffset === (heightVal*2) ){
scrollCheck = 2;
}
}//3rd photo, scroll up
else if( yValue < heightVal*2 && scrollCheck === 2){
$('body').stop().animate({scrollTop:(heightVal)}, 700, 'linear');
if ( window.pageYOffset === heightVal ){
scrollCheck = 1;
}
}
}//end of scrolling(e) funcion
}); //end of $(document).ready
html,body{
margin: 0;
height: 100%;
width: 100%;
}
#section1,#section2,#section3{
height: 100%;
width: 100%;
vertical-align: top;
}
#section1{
background-color: grey;
}
#section2{
background-color: green;
}
#section3{
background-color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='section1'></div>
<div id='section2'></div>
<div id='section3'></div>