Last active
October 8, 2015 00:10
-
-
Save LanF3usT/3247440 to your computer and use it in GitHub Desktop.
ScrollTo with #hash
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
# Console log | |
window.log = -> | |
console?.log?(arguments...) | |
# Vérification de l'historique du navigateur | |
history_enabled = -> | |
return Boolean( | |
window.history and window.history.pushState \ | |
and window.history.replaceState \ | |
and not (RegExp(" Mobile\\/([1-7][a-z]|(8([abcde]|f(1[0-8]))))", "i")).test(navigator.userAgent) or (/AppleWebKit\/5([0-2]|3[0-2])/i).test(navigator.userAgent) | |
) | |
# Au chargement du DOM | |
$(document).ready -> | |
# Si la présence d'un hash dans l'URL | |
if window.location.hash | |
# Suppression du hash de l'url | |
if history_enabled | |
href_without_hash = window.location.href.replace(/#.*/, '') | |
window.history.replaceState("", "", "#{href_without_hash}") | |
# Animation scroolTo | |
linkTo = $(window.location.hash) | |
$('body').stop().scrollTo linkTo, 1500, {offset:-225, easing:'quintEaseInOut'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment