我尝试在一些页面中使用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;
});
我希望这个想法清楚明了。
谢谢
非常重要的提示: 我上面发布的代码可以在同一页内很好地工作,但我想要的是从一个页面点击链接并转到另一个页面,然后滚动到目标位置。我希望现在清楚了。谢谢