在我的主頁底部,我已經包含了一個聯繫表單,併爲本節指定了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(聯繫人)對我來說只出現在一頁(家庭)上。