1
我已經獲得了此腳本,其中在加載和調整大小時設置主體的填充和用於錨點的類所以導航欄不會掩蓋目標。這是用於具有流暢圖像的導航欄,而且這些高度是可變的,這就是爲什麼我創建了這個腳本,但我對jQuery並沒有那麼熱。jQuery設置可變高度導航欄的高度,以便在導航欄上使用主體和類,以便導航不掩蓋目標
問題:我不知道如何減少重複性,負載和調整大小,他們不能工作,所以我不必重複?
鏈接:http://jsbin.com/iJaJAzIM/1/edit
//Adjust body and .anchortarget so that navbar doesn't cover up anchor
$(window).load(function() {
$('body').css({
"padding-top": $(".navbar").height() + "px"
});
$('.anchortarget').css({
"padding-top": $(".navbar").height() + "px"
}, {
"margin-top": $(".navbar").height() - "px"
});
});
$(window).resize(function() {
$('body').css({
"padding-top": $(".navbar").height() + "px"
});
$('.anchortarget').css({
"padding-top": $(".navbar").height() + "px"
}, {
"margin-top": $(".navbar").height() - "px"
});
});
'$(窗口)。在( '調整負荷',函數(){...' – adeneo
巖感謝!!! – Christina
升級:http://jsbin.com/iJaJAzIM/2/編輯 – Christina