Answer the question
In order to leave comments, you need to log in
Is it possible to remake the smooth scroll script?
There is a script for smooth scrolling triggered by href:
$(".slowly").on("click", function (event) {
/*Отменяем стандартную обработку нажатия по ссылке.*/
event.preventDefault();
/*Забираем идентификатор блока с атрибута href.*/
var id = $(this).attr('href'),
/*Узнаём высоту от начала страницы до блока, на который ссылается якорь.*/
top = $(id).offset().top;
/*Анимируем переход на расстояние - top за 1000ms.*/
$('body,html').animate({scrollTop: top}, 1200);
<form action="#tutorial" class="slowly">
<button class="button slogan-button hvr-bounce-in">
<span>Перейти!</span>
</button>
</form>
Answer the question
In order to leave comments, you need to log in
<button class="slowly" data-target="some_id">Take me there but slowly</button>
$(".slowly").on("click", function (event) {
/*Отменяем стандартную обработку нажатия по ссылке.*/
event.preventDefault();
/*Забираем идентификатор блока с атрибута href.*/
var id = $(this).attr('href') || $(this).attr('data-target');
/*Узнаём высоту от начала страницы до блока, на который ссылается якорь.*/
var top = $(id).offset().top;
/*Анимируем переход на расстояние - top за 1000ms.*/
$('body,html').animate({scrollTop: top}, 1200);
Make the button just a link <a href="#block">Перейти</a>
and style it like a button
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question