1

I have a fixed navigation bar on my bootstrap webpage. But once I animate the body element of my page the navigation bar scrolls with the page out of view.

I animate the body to 'fly in' from the right. This is done via this css:

@keyframes body-anim {
    0% {
        transform: translate(10rem);
        opacity: 0;
    }
    25% {
        opacity: 0;
    }
}

body {
    animation-name: body-anim;
    animation-duration: 2s;
    animation-fill-mode: forwards;
    animation-timing-function: ease-in-out;
    overflow-x: hidden;
}

This animation breaks my fixed-top-navigation bar which looks like this:

<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#"><span class="col-brand">B</span>rand</a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li><a href="#">Example</a></li>
            </ul>
        </div>
        <!-- /.navbar-collapse -->
    </div>
    <!-- /.container-fluid -->
</nav>

Have any idea why?

JSFiddle: https://jsfiddle.net/DTcHh/20315/

FabianTe
  • 516
  • 4
  • 22
  • 1
    can you drop full code on jsfiddle so it is easier to test? – Jakob May 06 '16 at 16:45
  • https://jsfiddle.net/DTcHh/20315/ here you go. Added a min-height to the body to simulate the page height. – FabianTe May 06 '16 at 17:20
  • 1
    hmmm... I can't see anything strange here. It slides in and works fine. What you mean by 'navigation bar scrolls with the page out of view'? I can see nav all the time. – Jakob May 06 '16 at 17:27
  • When I scroll down the page the fixed nav bar should by definition and the bootstrap example remain in view but when I try it, it scrolls away. It behaves like the navigation bar from stackoverflow (the black one on the very top) for example. But it should behave like this: https://getbootstrap.com/examples/navbar-fixed-top/ – FabianTe May 09 '16 at 07:14

1 Answers1

1

This is known issue when using css transform and fixed element like this.
Look at this answer 'transform3d' not working with position: fixed children

Quick fix would be to do translate like this:

transform: translate(10rem,0,0);

Although with this you lose that sliding animation and just get fadein.

Community
  • 1
  • 1
Jakob
  • 3,493
  • 4
  • 26
  • 42
  • I guess this is better than nothing, but there really isn't another way? – FabianTe May 14 '16 at 13:24
  • I don't know any other way with css. If you can use javascript then it can be done with jquery for example. – Jakob May 14 '16 at 15:22
  • Js is an option. I thought about applying the fixed rules bootstrap uses by myself after the animation is done. Might that work? – FabianTe May 14 '16 at 15:26
  • 1
    I used your solution and added a wow reveal option to a div containing everything but the nav bar and that did the trick. – FabianTe May 23 '16 at 08:03