在我的主页底部,我包含了一个联系表格,并将此部分的锚指定为 div id="contact"。
在任何页面上单击联系按钮时,它应该导航到主页并在页面加载时自动滚动到联系表格。
在查看了我在此处找到的类似问题后,我一直未能成功地使其工作: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(联系)对我来说只出现在一页(主页)上。