Home > Blockchain >  Bootstrap navbar transition not smooth
Bootstrap navbar transition not smooth

Time:10-29

I have the following HTML code for my bootstrap navbar.

<nav class="navbar navbar-expand-lg navbar-dark" style="background-color:
      rgb(50, 50, 50)">
        <button
          class="navbar-toggler"
          type="button"
          data-toggle="collapse"
          data-target="#navbar"
        >

         <h1><i class="fas fa-bars" ></i></h1>

        </button>

        <div class="collapse navbar-collapse" id="navbar">
          
          <div class="navbar-nav">
            <div>
              <a class="nav-item nav-link" id="signUp" href="/SignUp">
                <h1>Sign Up&nbsp;&nbsp;</h1></a>
              <a class="nav-item nav-link" id="login" href="/LoginOrDeleteAccount">
                <h1>Login Or Delete Account</h1></a>
            </div>
          </div>
        </div>
      </nav>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

I tried to change the speed the navbar collapses or expands by using the Css code below.

#navbar{
    transition:height 2s ease;
}
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

The code above works,but the navbar does not expand or collapse smoothly.How can I fix this problem?

CodePudding user response:

try changing the button attributes from data-toggle to data-bs-toggle and data-target to data-bs-target

<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar">

CodePudding user response:

Updated Working Snippet with Bootstrap 5.1 version

Bootstrap 5.1

Please check the following working snippet

<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg navbar-dark" style="background-color:
      rgb(50, 50, 50)">
    <button
      class="navbar-toggler"
      type="button"
      data-bs-toggle="collapse"
      data-bs-target="#navbar"
      aria-controls="navbar"
      aria-expanded="false"
      aria-label="Toggle navigation"
    >
     <h1><i class="fas fa-bars" ></i></h1>
    </button>

    <div class="collapse navbar-collapse" id="navbar">

      <div class="navbar-nav">
        <div>
          <a class="nav-item nav-link" id="signUp" href="/SignUp">
            <h1>Sign Up&nbsp;&nbsp;</h1></a>
          <a class="nav-item nav-link" id="login" href="/LoginOrDeleteAccount">
            <h1>Login Or Delete Account</h1></a>
        </div>
      </div>
    </div>
</nav>
      
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg OMhuP IlRH9sENBO0LRn5q 8nbTov4 1p" crossorigin="anonymous"></script>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Updated Working Snippet with Bootstrap 3.4.1 version

Note: Toggleable, contextual menu for displaying lists of links. Made interactive with the dropdown JavaScript plugin. Thant's mean you have to call dropdown via javascript

Ex:

// Call the dropdowns via JavaScript___
$('.dropdown-toggle').dropdown();

Please check the following working snippet

$('.dropdown-toggle').dropdown();
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN Bdg0JdbxYKrThecOKuH5zCYotlSAcp1 c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

<nav class="navbar navbar-expand-lg navbar-dark" style="background-color:
      rgb(50, 50, 50)">
    <button
      type="button" class="dropdown-toggle" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"
    >
     <h1><i class="fas fa-bars" ></i></h1>
    </button>

    <div class="dropdown-menu" id="navbar"class="dropdown-menu" aria-labelledby="dropdownMenu1">

      <div class="navbar-nav">
        <div>
          <a class="nav-item nav-link" id="signUp" href="/SignUp">
            <h1>Sign Up&nbsp;&nbsp;</h1></a>
          <a class="nav-item nav-link" id="login" href="/LoginOrDeleteAccount">
            <h1>Login Or Delete Account</h1></a>
        </div>
      </div>
    </div>
</nav>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
<iframe name="sif4" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related