Skip to content

Instantly share code, notes, and snippets.

@hiwelo
Last active October 23, 2015 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiwelo/f9599a7f87dcd9a08f2d to your computer and use it in GitHub Desktop.
Save hiwelo/f9599a7f87dcd9a08f2d to your computer and use it in GitHub Desktop.
Smooth scrolling lors des ancres internes
/**!
* 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