Machineghostの答えはとても役に立ちました。一緒にパッチを適用したコードは、URLパラメータを取得し、それをハッシュタグに変換します。このハッシュタグは、DOMの準備が整うとすぐにブラウザがスクロールします。
URLは次のようになります。
www.mysite.com/hello/world.htm?page=contact
連絡先は、スクロール先のIDの名前です
<h1 id="contact">Contact Us</h1>
コードは次のとおりです。
// Get any params from the URL
$.extend({
getUrlVars: function(){
var vars = [], hash;
var url = decodeURIComponent(window.location.href);
var hashes = url.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
},
getUrlVar: function(name){
return $.getUrlVars()[name];
}
});
$(document).ready(function() {
// Unhide the main content area
$('section.centered').fadeIn('slow');
// Create a var out of the URL param that we can scroll to
var page = $.getUrlVar('page');
var scrollElement = '#' + page;
// Scroll down to the newly specified anchor point
var destination = $(scrollElement).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-75}, 800 );
return false;
});
ChromeとFFでこれを確認したところ、非常にうまく機能しました。スクロールターゲットが目的の場所に正確に移動しない場合は、「destination-75」を調整してみてください。
上記の投稿がなければできなかったので、ありがとう!