Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. $(document).ready( function (){
  2. var scrollCheck = 0;
  3. var heightVal = window.innerHeight;
  4. var hControl1 = heightVal -1;
  5.  
  6. // below, making sure that var's are updated while resizing
  7.  
  8. $(window).resize(function(){
  9. window.scroll(0,0);
  10. heightVal = window.innerHeight;
  11. hControl1 = heightVal -1;
  12. scrollCheck = 0;
  13. });
  14.  
  15. $( window ).scroll(function() {
  16. var yValue = $(window).scrollTop();
  17.  
  18. //1st photo, scrolling down
  19. if ( yValue > 0 && scrollCheck === 0 ){
  20.  
  21. $('body').stop().animate({scrollTop:(heightVal)}, 500, 'linear');
  22. if ( window.pageYOffset === heightVal ){
  23. scrollCheck = 1;
  24. }
  25.  
  26. }
  27.  
  28. //2nd photo, scrolling up <- THE ONLY ONE where linear actually works as it should
  29.  
  30. else if( yValue < heightVal && scrollCheck === 1 ){
  31.  
  32. $('body').stop().animate({scrollTop:(-heightVal)}, 500, 'linear');
  33.  
  34. if ( window.pageYOffset === 0 ){
  35. scrollCheck = 0;
  36. }
  37. }
  38. //2nd photo, scrolling down
  39. else if( yValue > heightVal && scrollCheck === 1 ){
  40.  
  41. $('body').stop().animate({scrollTop:(heightVal*2)-1}, 500, 'linear');
  42. if ( window.pageYOffset === (heightVal*2)-1 ){
  43. scrollCheck = 2;
  44. }
  45.  
  46. }
  47. //3rd photo, scroll up
  48. else if( yValue < heightVal*2 && scrollCheck === 2){
  49. $('body').stop().animate({scrollTop:(hControl1)}, 500, 'linear');
  50. if ( window.pageYOffset === hControl1 ){
  51. scrollCheck = 1;
  52. }
  53. }
  54. });
  55.  
  56. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement