T
T
Toma2018-09-19 13:05:36
JavaScript
Toma, 2018-09-19 13:05:36

How to make simple scroll (no animation) to anchor without changing address bar (no jQuery on React)?

There is an element with id="testElement". There is a link Everything works ok, smoothness and animation are not needed, but now you need to learn how, for example, using js, scroll to the desired element without adding #testElement to the address bar (smoothness and animation are still not needed) React project. We need the simplest possible idea. <a href="#testElement">Прокрути</a>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-09-19
@tomatenshi

It couldn't be easier:
Demo
In the React implementation something like this:

handleLinkClick = e => {
  e.preventDefault();
  const element = document.getElementById(e.target.href);
  element.scrollIntoView();
};

R
Roman Alexandrovich, 2018-09-19
@RomReed

I think one of these will definitely help
https://stackoverflow.com/questions/43441856/react...
https://codedaily.io/tutorials/8/Build-a-Reusable-...
https://codepen. io/takatama/pen/mVvbqx

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question