一部のページ内でjQueryのページスクロールを使用しようとしていたところ、スムーズなページスクロールを正常に行うことができました。私が今持っている唯一の問題は、別のページからそれをしようとしたときです。つまり、ページ内のリンクをクリックすると、新しいページが読み込まれ、特定の div 要素までスクロールする必要があります。
ページ内をスクロールするために使用したコードは次のとおりです。
var jump=function(e)
{
//prevent the "normal" behaviour which would be a "hard" jump
e.preventDefault();
//Get the target
var target = $(this).attr("href");
//perform animated scrolling
$('html,body').animate(
{
//get top-position of target-element and set it as scroll target
scrollTop: $(target).offset().top
//scrolldelay: 2 seconds
},2000,function()
{
//attach the hash (#jumptarget) to the pageurl
location.hash = target;
});
}
$(document).ready(function()
{
$('a[href*=#]').bind("click", jump);
return false;
});
アイデアが明確であることを願っています。
ありがとう
非常に重要な注:上記のコードは同じページ内でうまく機能しますが、私が求めているのは、あるページからリンクをクリックして別のページに移動し、ターゲットまでスクロールすることです. それが今はっきりしていることを願っています。ありがとう