How can I scroll down to a specific block by pressing a button?
-
I have this button -
When I click on it, I need to scroll to the block with id = "cost".
These are not navigation anchors! I've already made the anchors.
You just need a simple scroll when you press the button and that's it.
How to do it?
I can't find the answer to the question anywhere.JavaScript Hunter Murillo, Mar 21, 2020 -
You can via scrollIntoViewAnonymous
-
If not an anchor, then what is it? https://developer.mozilla.org/en/docs/Web/CSS / scro ...
And you can, as in the old days, animate a scroll on jquery, or even on vanilla, but it's more difficult.
$('a[href^="#"]').on('click', function(event) {
var target = $( $(this).attr('href') );
if( target.length ) {
event.preventDefault();
$('html, body').animate({
scrollTop: target.offset().top
}, 500);
}
});Anonymous -
Scrolling but not anchor ... Why, why? Have you read about scroll-behavior ?Anonymous
3 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!