Javascript Jquery滚动内部/外部页面
我很抱歉问错了问题。然而,我发现了一篇帖子,问我到底想弄明白什么。我在这里找到了这个帖子: 使用下面的代码,我想了解如何使用a href=index.php/home处理内部和外部页面。另一篇文章展示了这个例子,但它不适用于内部页面 Javascript:Javascript Jquery滚动内部/外部页面,javascript,jquery,Javascript,Jquery,我很抱歉问错了问题。然而,我发现了一篇帖子,问我到底想弄明白什么。我在这里找到了这个帖子: 使用下面的代码,我想了解如何使用a href=index.php/home处理内部和外部页面。另一篇文章展示了这个例子,但它不适用于内部页面 Javascript: (function($) { var jump=function(e) { if (e){e.preventDefault();var target = $(this).attr("href");} else{var targ
(function($) {
var jump=function(e)
{
if (e){e.preventDefault();var target = $(this).attr("href");}
else{var target = location.hash;}
$('html,body').animate({scrollTop: $(target).offset().top},1100,function(){location.hash = target;});
}
$('html, body').hide();
$(document).ready(function()
{
$('a[href^=#]').bind("click", jump);
if (location.hash){
setTimeout(function(){$('html, body').scrollTop(0).show();jump()},0);
}
else{$('html, body').show()}
});
})(jQuery)
如果它位于站点的根目录,您可以这样做:
$('a[href="/#home"]').on("click", jump);
这将是一个简单的解决方案,如果你想匹配任何一个带有散列的页面,或者有其他限制发布它们,我会更新答案。我相信你想要
$('a[href="/#home"]').on("click", jump);
$('a[href^=#], a[href^="index.php#"]').bind("click", jump);
$('a[href$="index.php#home"]').bind("click", jump);