gpt4 book ai didi

php - 导航位置固定在滚动 wordpress 上

转载 作者:行者123 更新时间:2023-11-28 16:41:56 26 4
gpt4 key购买 nike

我想知道如何才能达到类似这个网站的效果。当您向下滚动网站时, Logo 消失但菜单保持不变:

http://www.nowness.com/

这是我的网站:http://www.itsalifestylething.co.uk/quick-cupcake-catch-up/

PHP

<body <?php body_class(); ?>>
<div id="page" class="hfeed site">
<header id="masthead" class="site-header" role="banner">

<hgroup>
<h1 class="site-title"><img src="http://www.itsalifestylething.co.uk/wp-content/uploads/2013/11/logo-large.png" /></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</hgroup>

<nav id="site-navigation" class="main-navigation" role="navigation">

<h3 class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></h3>
<a class="assistive-text" href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a>
<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>

</nav><!-- #site-navigation -->

<?php if ( get_header_image() ) : ?>
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php header_image(); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /></a>
<?php endif; ?>
</header><!-- #masthead -->

<div id="main" class="wrapper">

CSS

/* Header
------------------------------------------------------------ */
.site-header {
padding: 5px 0 !important;
}

hgroup {
width: 100%;
}

#masthead {
width: 960px;
margin: 0 auto;
position: relative;
}

h1.site-title {
margin: 0 auto;
width: 480px;
height: 123px;
}

.social img {
margin-right: 15px;
}

/* Nav
------------------------------------------------------------ */
.main-navigation {
width: 100%;
margin: 0px !important;
}

.main-navigation div.nav-menu > ul {
border: 0px !important;
margin: 0 auto;
width: 430px;
}

.main-navigation li {
margin: 0 25px 0 0;
}

.main-navigation li ul {
padding-top: 2px;
z-index: 10;
}

.main-navigation li a:hover, .main-navigation .current_page_item > a {
color: #33d898;
font-weight: normal;
}

.main-navigation li ul {
-webkit-box-shadow: 0px 5px 10px 1px rgba(0,0,0,0.2);
box-shadow: 0px 5px 10px 1px rgba(0,0,0,0.2);
width: 200px;
}

.main-navigation li ul li a {
background: #ffffff;
border-bottom: 1px solid #e7e7e7
}

.main-navigation li ul li a:hover {
background: #ffffff;
color: #33d898;
}

.nav-menu {
border-bottom: 1px solid #e7e7e7;
}

最佳答案

这就是我使用 htmlcssjQuery 的方式。

首先,这就是我订购 html 的方式,

<nav>
<span class="logo">Your Logo</span>
<ul>
<li id="logo">Your Logo</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</nav>

接下来是css

html, body {
margin: 0;
padding: 0;
}

ul {
margin: 0;
padding: 0;
list-style-type: none;
}

nav {
width: 80%;
background: #c1c1c1;
position: fixed;
top: 0;
left: 50%;
margin-left: -40%;
}

nav li {
display: inline-block;
cursor: pointer;
}

#logo {
display: none;
}

#logo.scroll {
display: inline-block;
}

.logo {
font-size: 50px;
font-family: "century gothic";
}

最后一点点jQuery

$(window).scroll(function() {
$('.logo').hide();
$('#logo').addClass('scroll');

if ($(window).scrollTop() === 0) {
$('.logo').show();
$('#logo').removeClass('scroll');
}
});

这是一个 jsfiddle,Link .

关于php - 导航位置固定在滚动 wordpress 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20227606/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com