D
D
DmSS19972021-06-11 12:15:55
JavaScript
DmSS1997, 2021-06-11 12:15:55

How to make a multilevel dropdown menu drop down more smoothly using Jquery?

This is what the html code looks like

<ul class="menu my-5" >
        <li><a href="">Menu</a>
          <ul>
            <li><a href="">Sub-Menu</a>
              <ul>
                <li><a href="">Sub-Sub-Menu</a></li>
                <li><a href="">Sub-Sub-Menu</a></li>
                <li><a href="">Sub-Sub-Menu</a></li>
              </ul>
            </li>
            <li><a href="">Sub-Menu</a>
              <ul>
                <li><a href="">Sub-Sub-Menu</a></li>
                <li><a href="">Sub-Sub-Menu</a></li>
                <li><a href="">Sub-Sub-Menu</a></li>
              </ul>
            </li>
            <li><a href="">Sub-Menu</a></li>
            <li><a href="">Sub-Menu</a></li>
            <li><a href="">Sub-Menu</a>
              <ul>
                <li><a href="">Sub-Sub-Menu</a></li>
                <li><a href="">Sub-Sub-Menu</a></li>
                <li><a href="">Sub-Sub-Menu</a></li>
              </ul>
            </li>
            <li><a href="">Sub-Menu</a></li>
            <li><a href="">Sub-Menu</a></li>

          </ul>
        </li>
        <li><a href="">Menu</a>
        </li>
      </ul>


This is what the css code looks like:
.menu{
      display: block;
      position: relative;
      justify-content:center;
      margin-left: 30%;

    }
    .menu li{
      width: 190px;
      list-style: none;
      /*background-color: #0275d8;*/
      position: relative;
      padding: 1.5px;
      margin-top: 1px;
      text-align: center;
    }
    .menu a{
      color:white;
      text-decoration: none;
      background-color: #dc3545;;
      
      display: block;
      text-align: center;
      padding-top:15px;
      transition: all 0.8s;
    }
    .menu a:hover{
      color:white;
      background-color: #d97777;
      cursor: default;

    }
    .menu ul{
      position: relative;
      display: none;
      top:-105px;
      left:155px;


    }

    .menu li:hover > ul{
      display: block;

    }
    .menu ul ul {
      display: none;
      position: absolute;

    }


Due to the fact that css uses display, and not visibility and opacity , it is impossible to set the animation. You need to do it through scripts. I don't know much about jquery, so please help me to write some jquery code for me to make it drop out more smoothly. I tried to do it myself, but it did not work out very well. The menu began to fall out smoothly, but all at once (

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
NQUARE, 2021-06-11
@NQUARE

Use opacity instead of display and add a transition.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question