Scroll to Divs on click, Inventrom Project

I haven’t been able to come up with a solution to scroll to Divs when I click one of the options in the navigation tab. I did however find a solution on a forum, is it okay if I use it? I haven’t really understood it but it works.

Hi @iamkshitijgaur,

Yes, you can use it. It will be great if you can share some code snippet and screen recording of the working system.

1 Like

//for scroll to div (Got the code from Stack Overflow)

$(document).on(‘click’, ‘a[href^="#"]’, function (event) {

event.preventDefault();

$('html, body').animate({

    scrollTop: $($.attr(this, 'href')).offset().top

}, 500);

});

inventrom1

Hi @iamkshitijgaur,

Uploaded image is not visible. Can you edit your previous thread and upload the image again.

The simple solution to scroll a div is by using anchor

<a href="#scroll-to">Home<a/>

<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>
<p>other sections</p>

<section id="scroll-to">
<p>it will scroll down to this section</p>
</section>

When you click on the Home then it will go down to the section where id scroll-to

Do let me know in case you need further assistance.

1 Like

Sir @rahul.singh, the solution you just sent worked. Regarding the previous thread, what I tried to upload was a gif of recording of the working system, I tried to upload it in the form of MP4 but it didn’t happen.

Hi @iamkshitijgaur,

You can upload the video to google drive and then share the public link of the video on the forum.

1 Like

https://drive.google.com/file/d/1s5pienG6JVeYCXrmT1ky4gHxodd0tmcL/view?usp=sharing
Here’s the link.

Hi @iamkshitijgaur,

As I can see in the video, your issue is resolved.

Do let me know in case you need any other information.

1 Like

Sir @rahul.singh, I’ve submitted the project, I wanted to know when I’ll get the certificate.