Skip to content

Instantly share code, notes, and snippets.

@sealucky7
Last active October 11, 2017 15:39
Show Gist options
  • Save sealucky7/00820a1177396b54aaac606af540529e to your computer and use it in GitHub Desktop.
Save sealucky7/00820a1177396b54aaac606af540529e to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$("a").click(function () {
var elementClick = $(this).attr("href")
var destination = $(elementClick).offset().top;
jQuery("html:not(:animated),body:not(:animated)").animate({scrollTop: destination - 300}, 800);
return false;
});
/*--------------------- Second method -------------------------*/
// прячем кнопку #back-top
$("#back-top").hide();
// появление/затухание кнопки #back-top
$(function (){
$(window).scroll(function (){
if ($(this).scrollTop() > 100){
$('#back-top').fadeIn();
} else{
$('#back-top').fadeOut();
}
});
// при клике на ссылку плавно поднимаемся вверх
$('#back-top a').click(function (){
$('body,html').animate({
scrollTop:0
}, 800);
return false;
});
});
});
<p id="back-top">
<a href="#top"><span></span>Вверх</a>
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment