Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var currentSection = 0;
- var totalSections = document.querySelectorAll("section").length;
- $(document).on('click', '.cd-go', function(event){
- event.preventDefault();
- var viewportHeight = $(window).height();
- currentSection++;
- if (currentSection > totalSections - 1) currentSection = totalSections - 1;
- $('html, body').animate({
- scrollTop: viewportHeight * currentSection
- }, 500);
- });
- var currentSection = 1;
- var nextSection = 0
- $(document).on('click', '.cd-go', function(event){
- var sec = 1;
- event.preventDefault();
- $("section").each(function(){
- if($(this).inView()){
- currentSection = sec;
- console.log('currentSection =',currentSection);
- }else{
- sec++
- }
- });
- nextSection = currentSection+1;
- var os = $('#section'+nextSection).offset();
- $('html, body').animate({
- scrollTop: os.top,
- scrollLeft: os.left
- });
- });
- $.fn.inView = function(){
- var elementTop = $(this).offset().top;
- var elementBottom = elementTop + $(this).outerHeight();
- var viewportTop = $(window).scrollTop();
- var viewportBottom = viewportTop + $(window).height();
- return elementBottom > viewportTop && elementTop < viewportBottom;
- };
Add Comment
Please, Sign In to add comment