scroll rotates and stops at the div below

Asked

Viewed 83 times

1

I’m developing a website and I’m having a problem. I want to create the website presented some products, and I want to scroll the scroll, the site runs to a certain size stopping in the position I want.

Let’s say the page rolls from 200px to 200px. Thus, the site is fixed on each div list of products. Please help me in this.

  • 1

    There are many questions about this feature and even scroll to the next element. Take a look here and you will find examples. Your question as it is is a little vague...

  • sorry my lack of knowledge in the area turns out to be difficult, and I’m not able to find anything on the subject. can help me ??

1 answer

0

Opa!

In this link, there is a lot of information about a type of function, called onscroll.

https://developer.mozilla.org/en-US/docs/Web/API/Window/onscroll

Basically, what it does is it acts on a drive specified by you.

For example:

  1. Imagine the case where you run a page in a certain amount (for example, the 500px you specified).

  2. Once you reach the amount of pixels you want, pass to this function a link that redirects to the particular div, with the ID you pass, and simulate a click.

Exemplifying more:

const scrollPixelsFunction = () => (
  const link = document.getElementById('linkWhenClick');
  return link.click()
);

window.onscroll = scrollPixelsFunction;
<div id="Scroll_pixels">
  <p>Olá</p>
</div>

But you need to improve the function further, of course. Just pass to it the amount of pixels you want to be directed from. For this, take a look at the link. He explains about the definition of pixels, which is what you asked.

I don’t know if it’s good practice, but I think having the path makes it easier for you to find good manners.

Success.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.