Guest User

Untitled

a guest
Jun 18th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. var currentSection = 0;
  2. var totalSections = document.querySelectorAll("section").length;
  3. $(document).on('click', '.cd-go', function(event){
  4. event.preventDefault();
  5. var viewportHeight = $(window).height();
  6. currentSection++;
  7. if (currentSection > totalSections - 1) currentSection = totalSections - 1;
  8. $('html, body').animate({
  9. scrollTop: viewportHeight * currentSection
  10. }, 500);
  11. });
  12.  
  13. var currentSection = 1;
  14. var nextSection = 0
  15.  
  16. $(document).on('click', '.cd-go', function(event){
  17. var sec = 1;
  18. event.preventDefault();
  19. $("section").each(function(){
  20. if($(this).inView()){
  21. currentSection = sec;
  22. console.log('currentSection =',currentSection);
  23. }else{
  24. sec++
  25. }
  26. });
  27. nextSection = currentSection+1;
  28.  
  29. var os = $('#section'+nextSection).offset();
  30.  
  31. $('html, body').animate({
  32. scrollTop: os.top,
  33. scrollLeft: os.left
  34. });
  35. });
  36.  
  37. $.fn.inView = function(){
  38. var elementTop = $(this).offset().top;
  39. var elementBottom = elementTop + $(this).outerHeight();
  40.  
  41. var viewportTop = $(window).scrollTop();
  42. var viewportBottom = viewportTop + $(window).height();
  43.  
  44. return elementBottom > viewportTop && elementTop < viewportBottom;
  45. };
Add Comment
Please, Sign In to add comment