Full Page Intro with fixed, transparent Navbar not working


Topic: Full Page Intro with fixed, transparent Navbar not working

Justin Espiritu free asked 2 years ago

Expected behavior

  • Navbar to change color when scrolling from top
  • Navbar to dynamically add top-nav-collapse class when scrolling from top.

Actual behavior

  • Navbar stays transparent when scrolling from top
  • Nav element class does not change, top-nav-collapse class is not added to nav class

Resources (screenshots, code snippets etc.)

Note

Have checked the forums for a solution. Seems like others had this issue but no solutions have been posted.


Konrad Stępień staff commented 2 years ago

Hi @Justin Espiritu,

Some examples require repair.

But I wanted to make sure you are a pro user because this page indicates that MDB Pro is required


Justin Espiritu free commented 2 years ago

I am not a pro user. I am looking at this page: https://mdbootstrap.com/docs/angular/navigation/compositions/ It doesn't state that I need to be a pro for that functionality.


Konrad Stępień staff answered 2 years ago

Hi @Justin Espiritu,

This code works correctly for me:

  <header class="h-100">
    <mdb-navbar SideClass="navbar fixed-top navbar-expand-lg navbar-dark scrolling-navbar intro-fixed-nav" [containerInside]="false">
      <mdb-navbar-brand>
        <a class="logo navbar-brand" href="#">
          <strong>Navbar</strong>
        </a>
      </mdb-navbar-brand>
      <links>
        <ul class="navbar-nav mr-auto">
          <li class="nav-item active waves-light" mdbWavesEffect>
            <a class="nav-link">Home
              <span class="sr-only">(current)</span>
            </a>
          </li>
          <li class="nav-item waves-light" mdbWavesEffect>
            <a class="nav-link">Link</a>
          </li>
          <li class="nav-item waves-light" mdbWavesEffect>
            <a class="nav-link">Profile</a>
          </li>
        </ul>
      </links>
    </mdb-navbar>
    <!-- Main -->
    <div class="view intro-2">
      <div class="full-bg-img">
        <div class="mask rgba-purple-light flex-center">
          <div class="container text-center white-text wow fadeInUp">
            <h2>This Navbar is fixed and transparent</h2>
            <br>
            <h5>It will always stay visible on the top, even when you scroll down</h5>
            <p>Navbar's background will switch from transparent to solid color while scrolling down</p>
            <br>
            <p>Full page intro with background image will be always displayed in full screen mode, regardless of device </p>
          </div>
        </div>
      </div>
    </div>
    <!-- /.Main -->
  </header>
  <!--Main Navigation-->

  <!--Main Layout-->
  <main class="text-center py-5">

    <div class="container">
      <div class="row">
        <div class="col-md-12">

          <p align="justify">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna
            aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
            Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur
            sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum
            dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
            Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis
            aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
            occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

        </div>
      </div>
    </div>

  </main>
  <!--Main Layout-->

And SCSS (But you have paste this code for your global file. styles.scss)

.view {
    background: url("https://mdbootstrap.com/img/Photos/Others/img (40).jpg")no-repeat center center;
    background-size: cover;
    height: 100vh;
}

.navbar {
    background-color: transparent;
}

.top-nav-collapse {
    background-color: #4285F4;
}

@media only screen and (max-width: 768px) {
    .navbar {
        background-color: #4285F4;
    }
}

Can you test my code?

Best, Konrad.


Justin Espiritu free commented 2 years ago

I have tested that code in my solution and still have the same issue of the top-nav-collapse class not dynamically being removed/added to the nav bar. I have put all the styling in the global scss.

When playing with the code on the demo it works perfectly fine.


Konrad Stępień staff commented 2 years ago

Hi @Justin Espiritu,

Can you send me some screenshots or something else? Maybe you can make project on GitHub and send me a link?


Justin Espiritu free commented 2 years ago

@Konrad Stępień Sorry for the late reply. Here is a link to the github project https://github.com/JuicyJuice1100/juice-becky-wedding.

I didn't push the code with the you pushed but it can easily be added. I originally tried to add it to the nav component. I also tried in the app, and home component as well.


Konrad Stępień staff commented 2 years ago

@Justin Espiritu,

Problem is in the styles.scss. You have to remove these lines:

html,
body {
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

And add this:

.top-nav-collapse {
  background-color: #4285F4;
}

@media only screen and (max-width: 768px) {
  .navbar {
      background-color: #4285F4;
  }
}

I added PR for your repo.

Best, Konrad.


Justin Espiritu free commented 2 years ago

@Konrad Stępień

That has fixed the issue. Thanks


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 8.10.0
  • Device: PC
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: Yes