Smooth scroll to div id jQuery

0 votes

I've been trying to get a scroll to div id jquery code to work correctly. Based on another stack overflow question i tried the following

DEMO http://jsfiddle.net/kevinPHPkevin/8tLdq/

$('#myButton').click(function() {
   $.scrollTo($('#myDiv'), 1000);
});

But it didn't work. It just snaps to the div. I also tried

$('#myButton').click(function(event) {
     event.preventDefault();
   $.scrollTo($('#myDiv'), 1000);
});

With no progress.

Jun 23 in Web Development by gaurav
• 18,040 points
9 views

1 answer to this question.

0 votes

You need to animate the html, body

$("#button").click(function() {
    $('html, body').animate({
        scrollTop: $("#myDiv").offset().top
    }, 2000);
});

Hope it helps!!
Thank you!!

answered Jun 23 by rajatha
• 7,040 points

Related Questions In Web Development

0 votes
0 answers

Scroll / Jump to id without jQuery

I have search a lot of topics ...READ MORE

Jul 28 in Web Development by gaurav
• 18,040 points
6 views
0 votes
0 answers

scroll up and down a div on button click using jquery

I am trying to add a feature ...READ MORE

Jun 29 in Web Development by gaurav
• 18,040 points
218 views
0 votes
1 answer

Not able to show/hide div which is nearest to checkbox using JQuery

pretty simple: $('.check-hide-show-content').hide(); // hide all content divs // ...READ MORE

answered Aug 2 in Web Development by rajatha
• 7,040 points
16 views
0 votes
1 answer

How to download a file by jQuery.Ajax?

Hello @kartik, You don't need to do this ...READ MORE

answered Sep 18, 2020 in Web Development by Niroj
• 82,740 points
5,614 views
0 votes
1 answer

Smooth scrolling when clicking an anchor link

document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', ...READ MORE

answered Jun 20 in JQuery by rajatha
• 7,040 points
12 views
0 votes
0 answers

Scroll to an element with jQuery

I have this input element: <input type="text" class="textfield" ...READ MORE

Jul 1 in Web Development by gaurav
• 18,040 points
14 views
0 votes
0 answers

How to scroll to top of page with JavaScript/jQuery?

Is there a way to control browser ...READ MORE

Jul 1 in Web Development by gaurav
• 18,040 points
36 views
0 votes
0 answers

Smooth scrolling when clicking an anchor link

My page has a few hyperlinks. When ...READ MORE

Jul 22 in CSS by Edureka
• 10,240 points
18 views
0 votes
1 answer

How to hide a div with jQuery?

We hide the divs by adding a CSS ...READ MORE

answered Jun 27 in Web Development by rajatha
• 7,040 points
23 views
0 votes
1 answer

How to detect current element id in jQuery?

Use the jQuery attr() Method You can simply ...READ MORE

answered Jun 30 in Web Development by rajatha
• 7,040 points
14 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP