This script gets the href attribute from the element and scroll the window down to that location.
          Created
          September 25, 2015 14:44 
        
      - 
      
- 
        Save lukewhitehouse/50777eb273e99d9137b0 to your computer and use it in GitHub Desktop. 
    Scroll to element on click
  
        
  
    
      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
    
  
  
    
  | $('.anchor').on('click', function(e) { | |
| var scrollLocation = $(this).attr('href'); | |
| $('html, body').animate({ | |
| scrollTop: $(scrollLocation).offset().top*.7 | |
| }, 550); | |
| if(history.pushState) { | |
| history.pushState(null, null, scrollLocation); | |
| } else { | |
| location.hash = scrollLocation; | |
| } | |
| return false; | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment