$(document).ready(function($) { $('#toggle-nav').click(function() { $(this).toggleClass('open'); $('body').toggleClass('nav-open nav-closed'); return false; }); // Resize Window $(window).resize(function () { if (this.resizeTO) clearTimeout(this.resizeTO); this.resizeTO = setTimeout(function () { $(this).trigger('resizeEnd'); }, 100); }); $(window).bind('resizeEnd', function () { var width = $(window).width(); if (width >= 600) { var sticky = $('div.sticky-anchor').length; if (sticky == 1) { function sticky_relocate() { var window_top = $(window).scrollTop(); var div_top = $('.sticky-anchor').offset().top; if (window_top > div_top) { $('.sticky').addClass('fixed'); } else { $('.sticky').removeClass('fixed'); } } $(function () { $(window).scroll(sticky_relocate); sticky_relocate(); }); } else { return; } } else { return; } }); $(window).trigger('resizeEnd'); $.event.special.throttledScroll = { setup: function(data) { var timer = 0; $(this).on('scroll.throttledScroll', function(event) { if (!timer) { timer = setTimeout(function() { $(this).triggerHandler('throttledScroll'); timer = 0; }, 250); } }); }, teardown: function() { $(this).off('scroll.throttledScroll'); } }; $(window).on('throttledScroll',function () { var pageScroll = $(document).scrollTop(); var width = $(window).width(); // console.log(pageScroll); if (pageScroll >= 150) { $('#fixed').removeClass('fixed-nav-hide').addClass('fixed-nav-show'); // console.log('success!'); } else { $('#fixed').removeClass('fixed-nav-show').addClass('fixed-nav-hide'); // console.log('yay!'); } }).trigger('throttledScroll'); $('#sidebar-nav a').click(function() { var AnchorScroll = $(this).attr('data-scroll'); $.smoothScroll({ scrollTarget: '#' + AnchorScroll }); }); }); // END READY