How to Make Dropdown Menu with Pop-up Effect

Asked

Viewed 2,311 times

0

$(function () {
	$(".menu2").hide();

	$(".open").stop(true, true).mouseover(function() {		
        $(".menu2").fadeIn(100).animate({ top: '-50' }, 400);
    });	
  
    $(".open").mouseleave(function() {
      $(".menu2").stop(true, true).fadeTo('fast').animate({ top: '1' }, 100).hide();
    })
});
#conteudo{
	width:100%;
	height:300px;
	background:#36C;
	}
.menu{
	width:1365px;
	height:30px;
	background:#F00;
	margin:0px auto;
	}
.menu1{
	width:450px;
	height:30px;
	background:#FFF;
	}
.menu1 li{
	width:150px;
	height:30px;
	background:#FF0;
	list-style:none;
	float:left;
	} 
.menu2{
	width:150px;
	height:90px;
	background:;
	margin-top:50px;
	position:relative;
	display:block;
	}
.menu2 li{
	width:150px;
	height:30px;
	background:#C30;
	top:20px;
	position:relative;
}
.menu2 li:hover{
	width:150px;
	height:30px;
	background:#C60;
	top:20px;
	position:relative;
}
menu1 li ul li .open{
	widht:150px;
	height:500px;
	background:#096;
	position:absolute;
	display:block;
	}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="conteudo">
  <nav class="menu">
    <ul class="menu1">
      <li>Teste1</li>
      <li class="open">Teste2
        <ul class="menu2">
          <li>Sub-Teste1</li>
           <li>Sub-Teste2</li>
         </ul>
      </li>
      <li>Teste3</li>
     </ul>
  </nav>    
</div>

Good night guys, all right? I’m looking for a way to make the dropdown menu, the operation of this menu is exactly as the link below: http://cssmenumaker.com/menu/textured-responsive-drop-down-menu.
I would like when the cursor is on top of the link, the submenu has the effect of appearing, as the link example.

  • 5

    Enter the code of what you tried, even if you’re wrong.

  • 2

    This link of yours is from a menu code generator you want. Below the example is a link to download a zip with all the code needed to generate this menu. That’s what you want?

  • First thank you for the prompt reply @bfavaretto. That’s right, I need to know how to do this menu, I analyzed the source code that is available for download, but I was a little confused, there is a simpler way to do this menu?

  • Hello @Reynan, all right? As the final result was not close to what I expected, I thought it best not to put it here, because I believe I’m doing it wrong! But if you prefer I can put it, what do you think?

  • 1

    Yes Israel, enter the code. But try to isolate the problem, and show only the parts that are not working. Take a look on this help page.

  • Israel, that comment directed to the bfavaretto can be made in the comments.

  • Good night @bfavaretto, I did the menu and so far it worked, the problem I’m having now is that when I pass the cursor many times and at a high speed in the movement of put and take it on top of the button that has the effect mouseover() it hangs. I put the example of the code I did above my question.

Show 2 more comments

2 answers

1


I don’t know if this is what you want. I usually use the bootstrap menu and it is also achieved by this effect. If you need help just say.

$(function () {
	$(".menu2").hide();

	$(".open").stop(true, true).mouseover(function() {		
        $(".menu2").fadeIn(100).animate({ opacity:'1' }, 400);
    });	
  
    $(".open").mouseleave(function() {
      $(".menu2").stop(true, true).fadeTo('fast').animate({ opacity: '0' }, 100).hide();
    })
});
#conteudo{
	width:100%;
	height:300px;
	background:#36C;
	}
.menu{
	width:1365px;
	height:30px;
	background:#F00;
	margin:0px auto;
	}
.menu1{
	width:450px;
	height:30px;
	background:#FFF;
	}
.menu1 li{
	width:150px;
	height:30px;
	background:#FF0;
	list-style:none;
	float:left;
	} 
.menu2{
	width:150px;
	height:90px;
	background:;
    opacity:0;
	position:relative;
	display:block;
-webkit-animation: KEYFRAME-NAME 5s infinite;
  -moz-animation:    KEYFRAME-NAME 5s infinite;
  -o-animation:      KEYFRAME-NAME 5s infinite;
  animation:         KEYFRAME-NAME 5s infinite;
	}
.menu2 li{
	width:150px;
	height:30px;
	background:#C30;
	top:20px;
	position:relative;
}
.menu2 li:hover{
	width:150px;
	height:30px;
	background:#C60;
	top:20px;
	position:relative;
}
menu1 li ul li .open{
	widht:150px;
	height:500px;
	background:#096;
	position:absolute;
	display:block;
	}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="conteudo">
  <nav class="menu">
    <ul class="menu1">
      <li>Teste1</li>
      <li class="open">Teste2
        <ul class="menu2">
          <li>Sub-Teste1</li>
           <li>Sub-Teste2</li>
         </ul>
      </li>
      <li>Teste3</li>
     </ul>
  </nav>    
</div>

0

Israel, I don’t quite understand what the purpose of your menu is, whether it’s just to study CSS and jquery or whether you’ll actually develop an application.

If it is the second case, I suggest using Bootstarp to save your development time. If it is the first case, I suggest using Bootstrap for you to use your study time in a professional tool, and that has been done to adapt to mobile devices, mobile phones, tablets etc.

This library is very easy and already does all the work for you. You don’t need to spend your developer time on the behavior and object design part because everything is already done, just copy and paste. There is a version of the site on portuguese, but I don’t know if the translation is complete yet. On the Bootstrap site you will already find many things, many types of menus. But if you are not satisfied, you can go to the site of Bootsnip and search for the object that interests you, in that case, menu. There you will find a huge variety of menus. If you want to learn Bootstrap and exactly with the menu of your question I suggest you the site of W3school.

I made 2 examples of dropdown:

//HTML
    <div class="dropdown">
  <button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Dropdown Example
  <span class="caret"></span></button>
  <ul class="dropdown-menu">
    <li><a href="#">HTML</a></li>
    <li><a href="#">Nivel 1</a></li>
    <li><a href="#">JavaScript</a></li>
  </ul>
</div>
<br/>
<br/>
<br/>                        
  <div class="dropdown">
    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">Tutorials
    <span class="caret"></span></button>
    <ul class="dropdown-menu">
      <li><a tabindex="-1" href="#">HTML</a></li>
      <li><a tabindex="-1" href="#">CSS</a></li>
      <li>
        <a class="test" tabindex="-1" href="#">New dropdown <span class="caret"></span></a>
        <ul class="dropdown-menu">
          <li><a tabindex="-1" href="#">2nd level dropdown</a></li>
          <li><a tabindex="-1" href="#">2nd level dropdown</a></li>
          <li>
            <a class="test" href="#">Another dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">3rd level dropdown</a></li>
              <li><a href="#">3rd level dropdown</a></li>
            </ul>
          </li>
        </ul>
      </li>
    </ul>
  </div>


//Js jQuery
$(document).ready(function(){
  $('.dropdown a.test').on("click", function(e){
    $(this).next('ul').toggle();
    e.stopPropagation();
    e.preventDefault();
  });
});

You basically work with HTML, minimal javascript and virtually zero css . Use the Bootstrap attributes and you’re done. Your menu will be smoking. Look at the example I created here link.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.