Last active
October 11, 2017 15:39
-
-
Save sealucky7/00820a1177396b54aaac606af540529e 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
$(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