在我的主页底部,我已经包含了一个联系表单,并为本节指定了div id =“contact”。链接到不同的页面 - > jquery滚动到特定的锚点
当任何页面上的联系人按钮被点击时,它应该导航到主页和页面加载,自动滚动到联系表格。
我在检查了一个类似的问题之后,在找到这里之后,我一直没有成功:jQuery scroll to ID from different page当我尝试时,它只是跳到表单。我想让它顺利滚动。
<li><span>Get in touch</span><a href="index.html#contact">Contact</a></li>
问题jQuery函数滚动到接触锚从其他网页主页上:
(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
},1000,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()
}
});
我想实现类似于此示例东西:http://vostrel.cz/so/9652944/page.html区别在于,代替在这种情况下出现在这两个页面上的“锚点ID”,锚点ID(联系人)对我来说只出现在一页(家庭)上。