Created
November 7, 2013 14:40
-
-
Save mikedugan/7355654 to your computer and use it in GitHub Desktop.
script to provide smooth scrolling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //User settings | |
| var maxSections = 5; | |
| var sectionNamePrefix = 'page-section'; | |
| var currSection = 1; | |
| function scrollToHash(e,sectionNumber) { | |
| var hash = '#' + sectionNamePrefix + sectionNumber; | |
| var target = $(hash); | |
| target = target.length ? target : $('[name=' + hash.slice(1) +']'); | |
| // e = event; | |
| if (target.length) { | |
| e.preventDefault(); | |
| $('html,body').stop().animate({ | |
| scrollTop: target.offset().top | |
| }, 600, function() { | |
| location.hash = hash; | |
| }); | |
| } | |
| } | |
| $(window).on('mousewheel', function(event, delta, deltaX, deltaY) { | |
| if (deltaY > 0) { | |
| if (currSection > 1) { currSection--; } | |
| scrollToHash(event,currSection); | |
| } | |
| else { | |
| if (currSection < maxSections) { currSection++; } | |
| scrollToHash(event,currSection); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment