Created
July 1, 2019 08:55
-
-
Save wireinet/ea8d4f28fb6a118ba6e65819741f2c2a 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(){ | |
var hashTagActive = ""; | |
$(".scroll").on("click touchstart" , function (event) { | |
if(hashTagActive != this.hash) { //this will prevent if the user click several times the same link to freeze the scroll. | |
event.preventDefault(); | |
//calculate destination place | |
var dest = 0; | |
if ($(this.hash).offset().top > $(document).height() - $(window).height()) { | |
dest = $(document).height() - $(window).height(); | |
} else { | |
dest = $(this.hash).offset().top; | |
} | |
//go to destination | |
$('html,body').animate({ | |
scrollTop: dest | |
}, 2000, 'swing'); | |
hashTagActive = this.hash; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment