我希望能够在向下滚动时停止页面顶部的导航栏。
我知道Jquery在某种程度上参与了解决方案,但我真的无法弄清楚如何使用它!
这是我的header.php文件(我在wordpress CMS上):
&GT; <?php if (has_nav_menu('top-menu', 'responsive')) { ?>
<?php wp_nav_menu(array(
'container' => '',
'fallback_cb' => false,
'menu_class' => 'top-menu',
'theme_location' => 'top-menu')
);
?>
<?php } ?>
<?php responsive_in_header(); // header hook ?>
<?php if ( get_header_image() != '' ) : ?>
<div id="logo">
<a href="<?php echo home_url('/'); ?>"><img src="<?php header_image(); ?>" width="<?php if(function_exists('get_custom_header')) { echo get_custom_header() -> width;} else { echo HEADER_IMAGE_WIDTH;} ?>" height="<?php if(function_exists('get_custom_header')) { echo get_custom_header() -> height;} else { echo HEADER_IMAGE_HEIGHT;} ?>" alt="<?php bloginfo('name'); ?>" /></a>
</div><!-- end of #logo -->
<?php endif; // header image was removed ?>
<?php if ( !get_header_image() ) : ?>
<div id="logo">
<span class="site-name"><a href="<?php echo home_url('/'); ?>" title="<?php echo esc_attr(get_bloginfo('name', 'display')); ?>" rel="home"><?php bloginfo('name'); ?></a></span>
<span class="site-description"><?php bloginfo('description'); ?></span>
</div><!-- end of #logo -->
<?php endif; // header image was removed (again) ?>
<?php get_sidebar('top'); ?>
<?php wp_nav_menu(array(
'container' => 'div',
'container_class' => 'main-nav',
'fallback_cb' => 'responsive_fallback_menu',
'theme_location' => 'header-menu')
);
?>
<?php if (has_nav_menu('sub-header-menu', 'responsive')) { ?>
<?php wp_nav_menu(array(
'container' => '',
'menu_class' => 'sub-header-menu',
'theme_location' => 'sub-header-menu')
);
?>
<?php } ?>
<?php responsive_header_bottom(); // after header content hook ?>
</div><!-- end of #header -->
<?php responsive_header_end(); // after header container hook ?>
<?php responsive_wrapper(); // before wrapper container hook ?>
<div id="wrapper" class="clearfix">
<?php responsive_wrapper_top(); // before wrapper content hook ?>
<?php responsive_in_wrapper(); // wrapper hook ?>
答案 0 :(得分:1)
答案 1 :(得分:0)
如果你希望它在向下滚动并回滚到之前状态后坚持到顶部,你可以使用Anthony Garand的Sticky jQuery Plugin。只需将其附加到您的菜单中,通常是:
$('.menu-main-menu-container').sticky({topSpacing:0});
答案 2 :(得分:0)
我认为您尝试做的事情可以通过jQuery Waypoints轻松完成:http://imakewebthings.com/jquery-waypoints/
你可以看到他们的&#34; Sticky&#34;这里的例子: http://imakewebthings.com/jquery-waypoints/shortcuts/sticky-elements/
如果这回答了您的问题,请标记为已接受。 :)