50886

Load page directly to anchor tag

When I load a page with a hash tag in the URL, the page loads and then jumps to the anchor tag. Is there any way to prevent this "jump", either by loading the page directly to the anchor tag or at least making the scrolling smooth?

I see this problem in Chrome and Firefox, but not IE.

Answer1:

If you're still experiencing the jumping issue, you could something with jQuery:

//Use a RegEx pattern to search for an id, if present var pattern = new RegExp('\#(.*)'); var id = pattern.exec(window.location)[0].replace('#',''); //Prevent the browser's default behavior of jumping to the id document.location = '#'; //When the page finishes loading, smoothly scroll to the specified content $(document).ready(function() { if(id != "") { $('html,body').animate({ scrollTop: $('#' + id).offset().top, }, 650); } });

Note that this will only work once per page load.

Recommend

  • Download file on page load not working
  • Cocos2d Jump Animation & Moving
  • Cutting down bag to pass to udf
  • How do I implement a picture instead of my red rectangle?
  • ViewExpiredException in Firefox and IE after migrating to Jboss 7.0 AS [duplicate]
  • How to animate float:left divs? [closed]
  • Replacing points of color by a uniform colored surface
  • Meteor stuck at Extracting meteor-tool@1.4.0-1
  • Android: how to determine cold start
  • Unable to click on the next page button containing “>” sign
  • Is there a way to set up a fallback for the formAction attribute in HTML5?
  • Problems with toDataURL HTML5 other ways to get canvas data?
  • joining two bezier curves
  • Django model inheritance, filtering models
  • Is playing sound in Javascript performance heavy?
  • Chrome doesn't support silverlight anymore? How to solve this?
  • $wpdb not working in file of WordPress plugin
  • Google Custom Search with transparent background
  • Insert into database using onclick function
  • Display issues when we change from one jquery mobile page to another in firefox
  • Ajax jQuery multiple calls at the same time - long wait for answer and not able to cancel
  • Different response to non-authenticated users and AJAX calls
  • What is Eclipse's Declaration View used for?
  • TFS: Get latest causes slow project reloading
  • Incrementing object id automatically JS constructor (static method and variable)
  • How to check if every primary key value is being referenced as foreign key in another table
  • Join two tables and save into third-sql
  • Can I make an Android app that runs a web view in Chrome 39?
  • Javascript convert timezone issue
  • Arrow is showed instead of the material design version hamburger icon. Why doesn't syncState in
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • How to model a transition system with SPIN
  • ORA-29908: missing primary invocation for ancillary operator
  • jquery mobile loadPage not working
  • Data Validation Drop Down Box Arrow Disappearing
  • How to delete a row from a dynamic generate table using jquery?
  • json Serialization in asp
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • How to stop GridView from loading again when I press back button?
  • Converting MP3 duration time