<li><a href="https://сайт.ru/#kkk" data-href="#kkk" title="" class="scroll">Как оформить</a></li>
<b>блок ссылки якоря</b>
<div id="kkk">Как оформить</div>
<script>
var w_hash = window.location.hash;
if (w_hash) {
setTimeout(function() {
window.scrollTo(0, 0);
}, 1);
}
$('html, body').stop().animate({
scrollTop: $(w_hash).offset().top
}, 777);
$(document).ready(function () {
$("a.scroll").on("click", function (e) {
var anchor = $(this);
$('html, body').stop().animate({
scrollTop: $(anchor.data('href')).offset().top
}, 777);
return false;
});
});
</script>
<script>
jQuery('a[href*="#"]')
// Remove links that don't actually link to anything
.not('[href="#"]')
.not('[href="#0"]')
.on('click', function(event) {
event.preventDefault();
// On-page links
var _this = jQuery(this), id = _this.attr('href').substring(_this.attr('href').indexOf('#'));
if(jQuery(id).length > 0) {
// Figure out element to scroll to
var target = jQuery(this.hash);
target = target.length ? target : jQuery('[name=' + this.hash.slice(1) + ']');
// Does a scroll target exist?
if (target.length) {
// Only prevent default if animation is actually gonna happen
event.preventDefault();
jQuery('html, body').animate({
scrollTop: target.offset().top
}, 1000, function() {
});
}
} else {
window.location.href = _this.attr('href');
}
});
var target = window.location.hash;
// delete hash so the page won't scroll to it
window.location.hash = "";
// now whenever you are ready do whatever you want
// (in this case I use jQuery to scroll to the tag after the page has loaded)
$(window).on('load', function() {
if (jQuery(target).length) {
$('html, body').animate({
scrollTop: jQuery(target).offset().top
}, 700, 'swing', function () {});
}
});
jQuery(function(){
if(jQuery(target).length > 0) {
jQuery('html, body').animate({
scrollTop: jQuery(target).offset().top
}, 1000, function() {
history.pushState(null,null, target);
});
}
return false;
});
</script>