Forked from manchumahara/gist:fdf41174a6ed79321978db91b85f8779
Created
August 20, 2019 13:23
-
-
Save mostafa6765/178f027aaa51773cf29bffeca3d7c1a6 to your computer and use it in GitHub Desktop.
This file contains 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($) { | |
$(document).ready(function($) { | |
//hash link click | |
$('a[href*="#"]').on('click', function(e) { | |
e.preventDefault(); | |
//console.log('hash clicked'); //uncomment this link to understand if click is working | |
var $this = $(this); | |
var $hash = $this.attr('href'); | |
var $link_hash = $this.prop("hash"); | |
//console.log($this.prop("hash")); | |
if ($link_hash != '' && $($link_hash).length > 0) { | |
//2# Hash link click for same page | |
$('html, body').animate({ | |
//scrollTop: $($(this).attr('href')).offset().top | |
scrollTop: parseInt($($link_hash).offset().top - 90) | |
}, 900, 'swing'); | |
} else if ($hash != $link_hash && $hash != '') { | |
//3# Hash based external link | |
window.location = $hash; | |
} | |
}); | |
}); | |
//1# Jump based on window hash url | |
var windowhash = window.location.hash; | |
if (windowhash != '' && $(windowhash).length > 0) { | |
$('html, body').animate({ | |
scrollTop: parseInt($(windowhash).offset().top - 90) | |
}, 900, 'swing'); | |
} | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment