/* var wh = 0; $(window).resize(function(){ wh = window.innerHeight; $('.block').height(wh); scrollPanels(); }).resize(); for (var i = 0; i < $('.block').length; i++) { $('.side-nav ul').append('
  • '); $('.side-nav').css({ 'top': wh - $(this).height()/2 }); } function scrollPanels() { var panels = $('.block'); for (var i = 0; i < panels.length; i++) { var offsetTop = $(panels[i]).offset().top; var offsetTopHalf = ($(panels[i]).height() / 2) + offsetTop; var offsetBot = $(panels[i]).height() + $(panels[i]).offset().top; $(panels[i]).attr('data-scroll-top', offsetTop); $(panels[i]).attr('data-scroll-half', offsetTopHalf); $(panels[i]).attr('data-scroll-bot', offsetBot); } $("html, body").bind("scroll mousedown DOMMouseScroll mousewheel keyup", function(){ $('html, body').stop(); }); $(window).scroll(function(){ var curPos = $(window).scrollTop(); clearTimeout($.data(this, 'scrollTimer')); $.data(this, 'scrollTimer', setTimeout(function(){ for (var i = 0; i < panels.length; i++) { var _index = $(panels[i]).index() + 1; if (curPos >= $(panels[i]).data('scroll-top') && curPos < $(panels[i]).data('scroll-bot')) { $('.side-nav li:nth-child(' + _index + ')').addClass('active'); if (curPos < $(panels[i]).data('scroll-half')) { $('html, body').animate({ scrollTop: $(panels[i]).data('scroll-top') }, 100); } else { $('body').animate({ scrollTop: $(panels[i]).data('scroll-bot') }, 100); } } else { $('.side-nav li:nth-child(' + _index + ')').removeClass('active'); } } },100)); }).scroll(); } */ $(window).resize(function(){ var h = $(window).height(); $(".block").css('height', h); }); $(window).resize(); $(window).on('scroll',function() { clearTimeout($.data(this, 'timer')); $.data(this, 'timer', setTimeout(function() { $('html, body').animate({ scrollTop: $('.block:hover').offset().top }, 100); event.preventDefault(); },400)); });