Skip to content
Fix Code Error

Smooth scroll to div id jQuery

March 13, 2021 by Code Error
Posted By: Anonymous

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.

Solution

You need to animate the html, body

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

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

Related Articles

  • Show scroll update when scrolling down page
  • How to parse the Manifest.mbdb file in an iOS 4.0…
  • Use of Jquery on scroll event
  • Fix top buttons on scroll of list below
  • Is it possible to apply CSS to half of a character?
  • Second animation with @keywords does not apply to div
  • In Pandas, how do I convert a number column to…
  • Show div on scrollDown after 800px
  • Active tab issue on page load HTML
  • Onclick, the button moves down, why can that due to?
  • Runing vue/cli app under docker simple index.html is opened
  • Javascript and SVG - move element with offset
  • Smooth scroll without the use of jQuery
  • Keeping the User logged in
  • After a little scroll, the sticky navbar just is not…
  • Retaining Scroll Position in Ember
  • @viewChild not working - cannot read property…
  • I'm having problems getting sql data in a table to…
  • Adobe XD to responsive html
  • Dynamically change bootstrap progress bar value when…
  • Accessing JPEG EXIF rotation data in JavaScript on…
  • vue.js cache video and play it
  • JavaScript Code not running on a Live Sever nor Local Host
  • show and hide previous and next button jQuery
  • How do I keep only the first map and when the game…
  • How to work out how to include jquery plugin with…
  • Download a file with Android, and showing the…
  • Dynamic classname inside ngClass in angular 2
  • Smooth scrolling when clicking an anchor link
  • jQuery.on() Delegation: Slightly complex selector…
  • Select DataFrame rows between two dates
  • Navbar not filling width of page when reduced to mobile view
  • core-scroll-header-panel + jQuery scroll
  • How to scroll to specific item using jQuery?
  • Python sort_values (inplace=True) but not really?
  • Having trouble with my nav bar/header, It used to…
  • jQuery Mobile: document ready vs. page events
  • Bootstrap Vue: How to make progress bar fill…
  • Form field border-radius is not working only on the…
  • jQuery get the location of an element relative to window
  • How to programmatically disable page scrolling with jQuery
  • Use jQuery to scroll to the bottom of a div with…
  • How to window.scrollTo() with a smooth effect
  • Calculator: Back key doesnt work in Javascript
  • Display progress bar while doing some work in C#?
  • How do i update a javascript variable as its value changes?
  • How to create a circle progress inside a Vue component
  • Adding custom parameter in vue2-dropzone event
  • How to make virtual scroll?
  • Twitter bootstrap progress bar animation on page load
  • Incorporate JQuery-file-upload to application
  • Android - How to download a file from a webserver
  • jQuery override default validation error message…
  • How to use html template with vue.js
  • Animating Elements in One by One
  • Javascript and css animation
  • Text Progress Bar in the Console
  • Pygame enemy not staying at the intended position on the map
  • How to scroll up or down the page to an anchor using jQuery?
  • How to add smooth scrolling to Bootstrap's scroll…
  • HTML table with 100% width, with vertical scroll…
  • How to loop through all the buttons to a click event…
  • Uncaught TypeError: Cannot read property 'top' of undefined
  • jQuery Scroll To bottom of the page
  • Vue-chat-scroll doesn't work with a loader
  • What is the use of the JavaScript 'bind' method?
  • Change the Bootstrap Modal effect
  • ScrollTo function in AngularJS
  • Replacing blank values (white space) with NaN in pandas
  • Animate scroll to ID on page load
  • Animate scroll effect to element in polymer using JQuery
  • When tab is selected, show next tab.. if last tab…
  • Why doesn't the height of a container element…
  • How to handle scroll position on hashchange in…
  • Do not close the mode in the mouse up event
  • Scrolling to an Anchor using Transition/CSS3
  • JavaScript SCROLLING in MVC PHP Software without…
  • scrollTop jquery, scrolling to div with id?
  • Scroll inside a div conten overflow text
  • Scroll to a div using jquery
  • Mobile browsers add a gap at the end of final…
  • Vue.js. Passing dynamically changing data to child component
  • I have an issue with initializing Jquery File upload plugin
  • Styling Google Polymer's paper slider element
  • Open a column of buttons when another button is…
  • How do I scroll to an element within an overflowed Div?
  • Smooth scroll to div in polymer element
  • Javascript text animation not triggering
  • jQuery .scrollTop(); + animation
  • Pause javascript setInterval when user scrolls up,…
  • CSS DIV width based on text length with position…
  • Axios all progress bar for multiple async uploads
  • Ember Run Loop and Bootstrap Progress Bar
  • PostgreSQL: No function matches the given name and…
  • Smoothing a curve with vectors made by few elements?
  • Reset/remove CSS styles for element only
  • Prevent body scrolling but allow overlay scrolling
  • Stack array using pop() and push()
  • How to unit-test the progress report of an async call?
  • Execution failed for task…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Find duplicate records in MySQL

Next Post:

File Upload using AngularJS

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error