我已经看了很多jquery示例,介绍了如何使菜单具有粘性。我已经在干净的html页面上应用了这些教程,它们非常有效。然而,当我尝试将其应用于“212”主题时,什么都没有发生。固定属性不会添加到menu类中。
这是CSS:
.sticky {
position: fixed;
width: 100%;
left: 0;
top: 0;
z-index: 100;
border-top: 0;
}
这是我的菜单:
<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 -->
这是JQUERY:
$(document).ready(function() {
var stickyNavTop = $(\'.main-navigation\').offset().top;
var stickyNav = function(){
var scrollTop = $(window).scrollTop();
if (scrollTop > stickyNavTop) {
$(\'.main-navigation\').addClass(\'sticky\');
} else {
$(\'.main-navigation\').removeClass(\'sticky\');
}
};
stickyNav();
$(window).scroll(function() {
stickyNav();
});
});
我错过什么了吗?