[英]When hiding/showing navigation bar, the nav bar is visible when the page is refreshed then disappears when I scroll
我創建了一個頁面,其中第二個導航欄在滾動時出現,並且在窗口位於頂部時應隱藏:0。刷新頁面時,導航欄可見,然后在滾動時消失,然后出現在scrollPos設置為顯示。
我如何使它在刷新頁面時被隱藏?
該網頁為www.fareastfestival.com,請尋求幫助。
這是我使用過的JS代碼:
$(document).ready(function() {
var navOffset = $("nav1").offset().top;
$("nav").wrap('<div class="nav-placeholder"></div>');
$(".nav-placeholder").height($("nav").outerHeight());
$(window).scroll(function(){
var scrollPos = $(window).scrollTop();
if (scrollPos >= navOffset) {
$("nav").removeClass("hide");
$("nav").addClass("fixed");
$(".navlogo").show();
}
else {
$("nav").addClass("hide");
$("nav").removeClass("fixed");
$(".navlogo").hide();
}
});
});
像<nav class="hide">
這樣,將hide類添加到html文件中的<nav class="hide">
只需將.hide類添加到HTML元素即可。 這是一個示例(第7行):
$(document).ready(function() {
var navOffset = $("nav1").offset().top;
$("nav").wrap('<div class="nav-placeholder"></div>');
$(".nav-placeholder").height($("nav").outerHeight());
$("nav").addClass("hide");
$(window).scroll(function(){
var scrollPos = $(window).scrollTop();
if (scrollPos >= navOffset) {
$("nav").removeClass("hide");
$("nav").addClass("fixed");
$(".navlogo").show();
}
else {
$("nav").addClass("hide");
$("nav").removeClass("fixed");
$(".navlogo").hide();
}
});
});
上面的代碼動態添加了該類。 您也可以將其添加到HTML中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.