(function( $ ) { 'use strict'; jQuery.scrollSpeed = function(step, speed) { var $document = $(document), $window = $(window), $body = $('html, body'), viewport = $window.height(), top = 0, scroll = false; if (window.navigator.msPointerEnabled) return false; $window.on('mousewheel DOMMouseScroll', function(e) { scroll = true; if (e.originalEvent.wheelDeltaY < 0 || e.originalEvent.detail > 0) top = (top + viewport) >= $document.height() ? top : top += step; if (e.originalEvent.wheelDeltaY > 0 || e.originalEvent.detail < 0) top = top <= 0 ? 0 : top -= step; $body.stop().animate({ scrollTop: top }, speed, 'default', function() { scroll = false; }); return false; }).on('scroll', function() { if (!scroll) top = $window.scrollTop(); }).on('resize', function() { viewport = $window.height(); }); }; jQuery.easing.default = function (x,t,b,c,d) { return -c * ((t=t/d-1)*t*t*t - 1) + b; }; $(function() { jQuery.scrollSpeed( 100, 800); }); //SMOOTH ANCHOR SCROLL $(document).ready(function(){ // Add smooth scrolling to all links $("a").on('click', function(event) { // Make sure this.hash has a value before overriding default behavior if (this.hash !== "") { // Prevent default anchor click behavior event.preventDefault(); // Store hash var hash = this.hash; // Using jQuery's animate() method to add smooth page scroll // The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area $('html, body').animate({ scrollTop: $(hash).offset().top }, 800, function(){ // Add hash (#) to URL when done scrolling (default click behavior) window.location.hash = hash; }); } // End if }); }); })( jQuery );