gpt4 book ai didi

html - 粘性菜单问题

转载 作者:行者123 更新时间:2023-11-28 06:22:17 26 4
gpt4 key购买 nike

我的 wordpress 网站上有一个粘性菜单,它只是一个带有固定 css 位置的标题,但它覆盖在我的每个部分的顶部。查看测试站点就可以明白我的意思了here

如果您单击菜单图标并单击一个部分,它将导航到每个部分,但我需要将粘性菜单放在每个部分上方,而不是覆盖在顶部。

在我的 header.php 中有

<div id="header-wrap">

<div class="poweredby">POWERED BY bluesource<p class="mobile-phone"><a href="tel: +44 0845 319 2100">0845 319 2100</a></p></div>

<div class="headerphone">0845 319 2100</div>

<button class="toggle-menu menu-right push-body"><i class="fa fa-bars"></i></button>

<!-- Right menu element-->

<?php if ( has_nav_menu( 'primary' ) || has_nav_menu( 'social' ) ) : ?>

<?php if ( has_nav_menu( 'primary' ) ) : ?>

<nav id="site-navigation" class="cbp-spmenu cbp-spmenu-vertical cbp-spmenu-right" role="navigation" aria-label="<?php esc_attr_e( 'Primary Menu', 'twentysixteen' ); ?>">
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'menu_class' => 'primary-menu',
) );
?>
</nav>

<?php endif; ?>

<?php endif; ?>

</div><!-- end header wrap -->

在我的样式表中有

.site-header {
background: #333 none repeat scroll 0 0;
height: 98px;
padding: 27px 0;
text-align: right;
}

.site-header-main {
text-align: right;
right: 0;
display: block;
padding-right: 27px;
}

#header-wrap {
background: #333;
position: fixed;
top: 0;
z-index: 100;
height: 98px;
padding-top: 27px;
padding-right: 27px;
opacity: 0.9;
}

最佳答案

这段代码可以做到

$('#header-wrap ul li a').click(function(){
href=$(this).attr('href');
$('html, body').animate({
scrollTop: $(href).offset().top-98 // since the height of your nav is 98px
}, 500);
});

对于外部链接

$(document).ready(function(){
var urlHash = window.location.href.split("#")[1];
$('html,body').animate({
scrollTop: $('#' + urlHash).offset().top-98
}, 500);
});

关于html - 粘性菜单问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35511602/

26 4 0