$(function() { $('a[href*=#]:not([href=#])').click(function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { $('html,body').animate({ scrollTop: target.offset().top }, 1000); return false; } } }); });
Check this link: http://css-tricks.com/snippets/jquery/smooth-scrolling/ for a demo, I’ve used it before and it works quite nicely.
Related Posts:
- Automatically pausing html5 video as the ‘next’ button is pressed (javascript/ jquery)
- Adding attribute in jQuery
- Get the value in an input text box
- jQuery.addClass not working
- Get checkbox value in jQuery
- How to make a simple modal pop up form using jquery and html?
- Bootstrap throws Uncaught Error: Bootstrap’s JavaScript requires jQuery
- jQuery checkbox event handling
- jquery – how to show a hidden div
- How to scroll to top of a div using jQuery?
- Check if a div exists with jquery
- Find out whether radio button is checked with JQuery?
- JQuery: ‘Uncaught TypeError: Illegal invocation’ at ajax request – several elements
- jquery ajax function not working
- jQuery find element by data attribute value
- Scroll to bottom of Div on page load (jQuery)
- Unblur content inside blurring background div
- How do I check whether a checkbox is checked in jQuery?
- What character encoding is >?
- Setting table column width
- What is difference between png8 and png24
- How can I set the default value for an HTML
- the use of `%3F` in URL
- Tab space instead of multiple non-breaking spaces (“nbsp”)?
- My website doesn’t work in I.E. (but does in chrome and firefox)
- Onclick javascript to make browser go back to previous page?
- Best way to encode Degree Celsius symbol into web page?
- How to place a text next to the picture?
- How do you create a hidden div that doesn’t create a line break or horizontal space?
- AngularJS ngClass conditional
- How to darken a background using CSS?
- How to solve PHP error ‘Notice: Array to string conversion in…’
- Hiding a button in Javascript
- Get HTML code using JavaScript with a URL
- Change Color of Fonts in DIV (CSS)
- Why is “cursor:pointer” effect in CSS not working
- How can I select an element by name with jQuery?
- a href link for entire div in HTML/CSS
- jQuery disable/enable submit button
- How to read if a checkbox is checked in PHP?
- Definition of ui-sref in Angular.js?
- mailto using javascript
- Complete list of reasons why a css file might not be working
- How to do auto-width with HTML IFrame
- Freeze the top row for an html table only (Fixed Table Header Scrolling)
- HTML list-style-type dash
- How can I make my footer center to the bottom of the page?
- Refresh/reload the content in Div using jquery/ajax
- “AutoComplete=Off” not working on Google Chrome Browser
- Why would max-width not work on this?
- Removing ul indentation with CSS
- Why write script type=”text/javascript” when the mime type is set by the server?
- RegEx match open tags except XHTML self-contained tags
- How to make a div 100% height of the browser window
- Why doesn’t min-height not work on my page?
- How to scroll an HTML page to a given anchor
- Difference between href and data-href in anchor tag in html
- button vs. input type=”button” /. Which to use?
- Javascript – ERR_CONTENT_LENGTH_MISMATCH
- Add stroke around text – on the outside – with css?
- Full Page < iframe >
- Change cursor to hand when mouse goes over a row in table
- CSS table td width – fixed, not flexible
- $(document).ready(function() is not working
- Favicon not working
- CSS max-height not working
- Override USER AGENT STYLE SHEET – Chrome
- aking a flex item float right
- wp_editor adds HTML entities to the content
- How to escape html code with html allowed
- How to Embed HTML files directly into WordPress
- Thumbnail + Excerpt = loss in word count
- How do you get words to show up at the bottom instead of beside a left-aligned photo? [closed]
- Migrating content from an old solution. How to easily change hardcoded hyperlinks in legacy content
- Show post in slider
- Embed tag length issues
- How put links in wordpress dynamic sidebar?
- How to add a class to the element?
- WordPress editor not creating tags properly in tables
- What doctype is considered best practice to use for WordPress?
- Remove tags from wordpress head
- Adding a slide toggle on WordPress
- render html no formatting
- hyphenation not working in Gutenberg editor
- All wordpress site went white blank screen
- How do I call a value from the datase using ajax
- Why is WordPress swapping double quotes (“) to curly quotes (“) and how do I stop it from happening?
- Display GIF as Facebook link thumbnail
- How to use wp_ajax_set_post_thumbnail?
- Change rel=”noopener noreferrer” to rel=’noopener noreferrer’ (single quote)
- How to add an ID to an existing HTML element?
- Site images are fixed in front of my site content [closed]
- Open popup automatically when navigate to the page id
- Displaying html table on post content
- What are the WordPress’ pre-formatted html components?
- can’t update plugins or wordpress or install new plugins [duplicate]
- How can I add a google play badge to my header and footer?
- Post title appears twice in browser title bar
- How to play a video after the end of another one via link?
- Moving from Microsoft Front Page 2003 to WordPress