Damir
Damir

Reputation: 342

Bootstrap 3 navigation bar resizes and changes logo when scroll

I want to be gain the effect of changing the logo to a more simpler version and have navigation fixed on top when I scroll down.

I've tried with some of the solutions I've found on stack overflow but I didn't manage to get the effect that I want.

I want to get this effect like on this website http://dootrix.com/

This is my code (I'm using WordPress and Bootstrap3):

<header>
    <div class="container-fluid full-width-menu navbar-fixed-top">
    <div class="container">
        <div class="row">
                <div class="logo img-responsive col-md-4">
                    <a class="logo-link" href="<?php echo get_bloginfo('url' ); ?>"><img src="<?php bloginfo('stylesheet_directory') ?>/images/logo.svg" /></a>
                </div> <!-- end logo -->    
                <div class=""> <!-- Menu -->
                    <nav class="main-menu navbar-inverse col-md-offset-2 col-md-6" role="banner">
                        <div class="navbar-header">
                          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                          </button>
                        </div>

                            <?php
                                wp_nav_menu( array(
                                    'menu'              => 'primary',
                                    'theme_location'    => 'primary',
                                    'depth'             => 1,
                                    'container'         => 'nav',
                                    'container_class'   => 'navbar-collapse bs-navbar-collapse collapse',
                                    'container_id'      => 'bs-example-navbar-collapse-1',
                                    'menu_class'        => 'nav navbar-nav no-gutter cl-effect-4',
                                    'fallback_cb'       => 'wp_bootstrap_navwalker::fallback',
                                    'walker'            => new wp_bootstrap_navwalker())
                                );
                            ?>
                    </nav>      
                </div> <!-- End menu -->
        </div> <!-- end row -->
    </div> <!-- end container -->
    </div> <!-- end container-fluid -->
    </div>
    </header>

I've only got that my navigation is fixed on top, but I want to be animated and load the smaller version of the logo.

Any suggestions?

Upvotes: 1

Views: 5798

Answers (1)

TeeDeJee
TeeDeJee

Reputation: 3741

They use this script on the dootrix site. (jQuery)

$(window).scroll(function(){
    if ( $(window).scrollTop() > 30 ) {
      $('.logo').addClass('scrolling');
    } else {
      $('.logo').removeClass('scrolling');
  }
});

So they add a class of scrolling to the header and then through css show the other logo.

<div class="logo img-responsive col-md-4">
  <a class="logo-link large-logo" href="<?php echo get_bloginfo('url' ); ?>"><img src="<?php bloginfo('stylesheet_directory') ?>/images/logo.svg" /></a>
  <a class="logo-link scrolling-logo" href="<?php echo get_bloginfo('url' ); ?>"><img src="<?php bloginfo('stylesheet_directory') ?>/images/scrolling-logo.svg" /></a>
</div> <!-- end logo -->  

css:

.large-logo {display:block;}
.scrolling-logo {display:none;}
.scrolling .large-logo {display:none;}
.scrolling .scrolling-logo {display:block;}

Upvotes: 2

Related Questions