M
M
myskypesla2017-10-12 21:35:43
JavaScript
myskypesla, 2017-10-12 21:35:43

How to write a vanilla js script to scroll to blocks?

How to catch a click on a menu item and scroll the page to a block with smooth animation?

I outlined the structure in jsfiddle

PS And tell me where to watch a video or read on such basics in native JS?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Peskov, 2019-07-09
@SergeyPeskov

Try to check if your field is complete before submitting the form using the isComplete() method. isComplete

I
Immortal_pony, 2017-10-12
@myskypesla

https://pawelgrzybek.com/page-scroll-in-vanilla-ja...

A
Andrei Smirnov, 2017-10-12
@pinebit

To scroll to the element, you have already assigned hash tags, it remains to add id to the blocks:
Then the browser itself will scroll to the element.
To catch a click, you need to use the onclick event:

<div class="block block-1" id="block-1" onclick="on_block1_click">

    // в скрипте:
    function on_block1_click() {
       alert("пользователь кликнул на block-1");
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question