Created
          March 2, 2016 20:02 
        
      - 
      
 - 
        
Save Ozerich/b08158c05abee909aaaf to your computer and use it in GitHub Desktop.  
  
    
      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
    
  
  
    
  | (function (global) { | |
| 'use strict'; | |
| function isHeaderFixed() { | |
| return $('.b-header--fixed').length > 0; | |
| } | |
| function getOffsetY(y) { | |
| var originalY = isHeaderFixed() ? y + 220 : y; | |
| if (originalY > 300) { | |
| return originalY - 300; | |
| } | |
| else { | |
| return originalY - 80; | |
| } | |
| } | |
| function doScroll(y) { | |
| $('html, body').animate({ | |
| scrollTop: getOffsetY(y) | |
| }); | |
| } | |
| var scroll = { | |
| scrollToY: function (y) { | |
| doScroll(y); | |
| }, | |
| scrollToElem: function (elem) { | |
| var $elem; | |
| if (typeof elem === 'string') { | |
| $elem = $(elem); | |
| } | |
| else{ | |
| $elem = elem; | |
| } | |
| if ($elem.length === 0) { | |
| return false; | |
| } | |
| return this.scrollToY($elem.first().offset().top); | |
| }, | |
| init: function () { | |
| var that = this; | |
| $('body').on('click', '.js-scroll[data-target]', function () { | |
| that.scrollToElem($(this).data('target')); | |
| return false; | |
| }); | |
| } | |
| }; | |
| $(function () { | |
| scroll.init(); | |
| }); | |
| global.Scroll = scroll; | |
| })(window); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment