Last active
October 23, 2015 15:17
-
-
Save hiwelo/f9599a7f87dcd9a08f2d to your computer and use it in GitHub Desktop.
Smooth scrolling lors des ancres internes
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
/**! | |
* Smoothscrolling to an id | |
* | |
* @contributors: Damien Senger (Alsacréations) | |
* @date-created: 2015-07-20 | |
* @last-update: 2015-07-20 | |
* */ | |
(function($) { | |
$(document).ready(function() { | |
$('a[href^="#"]').click(function() { | |
// when we click on an element | |
var width = $('body').width(), | |
target = $(this).attr('href'); | |
if ($(target).length && target != "#") { | |
var position = $(target).offset().top, | |
decalage = 200, | |
destination = position - decalage, | |
speed = 750; // Animation duration in ms | |
// we move to the destination | |
$('html, body').animate({ | |
scrollTop: destination, | |
}, speed); | |
} | |
// we cancel the click on this link | |
return false; | |
}); | |
}); | |
}(jQuery)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment