Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready( function (){
- var scrollCheck = 0;
- var heightVal = window.innerHeight;
- var hControl1 = heightVal -1;
- // below, making sure that var's are updated while resizing
- $(window).resize(function(){
- window.scroll(0,0);
- heightVal = window.innerHeight;
- hControl1 = heightVal -1;
- scrollCheck = 0;
- });
- $( window ).scroll(function() {
- var yValue = $(window).scrollTop();
- //1st photo, scrolling down
- if ( yValue > 0 && scrollCheck === 0 ){
- $('body').stop().animate({scrollTop:(heightVal)}, 500, 'linear');
- if ( window.pageYOffset === heightVal ){
- scrollCheck = 1;
- }
- }
- //2nd photo, scrolling up <- THE ONLY ONE where linear actually works as it should
- else if( yValue < heightVal && scrollCheck === 1 ){
- $('body').stop().animate({scrollTop:(-heightVal)}, 500, 'linear');
- if ( window.pageYOffset === 0 ){
- scrollCheck = 0;
- }
- }
- //2nd photo, scrolling down
- else if( yValue > heightVal && scrollCheck === 1 ){
- $('body').stop().animate({scrollTop:(heightVal*2)-1}, 500, 'linear');
- if ( window.pageYOffset === (heightVal*2)-1 ){
- scrollCheck = 2;
- }
- }
- //3rd photo, scroll up
- else if( yValue < heightVal*2 && scrollCheck === 2){
- $('body').stop().animate({scrollTop:(hControl1)}, 500, 'linear');
- if ( window.pageYOffset === hControl1 ){
- scrollCheck = 1;
- }
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement