Menu Hover Jquery

Asked

Viewed 138 times

0

How can I fix that hover to be able to click the link button? I always have problems with submenus, if anyone can help.

$(function(){
 $('.menu-toltip').hover(function(){
 $(this).find('a').first().addClass('hover');
 $(this).find('.square').first().addClass('hover');
 $(this).find('.box-toltip').animate({
  "left":"7px",
  opacity:1
  },300);
},function(){
 $(this).find('a').removeClass('hover');
 $(this).find('.square').first().removeClass('hover');
 $(this).find('.box-toltip').animate({
  "left":"50px",
  opacity:0
  },300);
  });
});    
.dots{
background: #ee1d47;
display: inline-block;
width: 30px;
height: 30px;
line-height: 29px;
border-radius: 50%;
color: #fff;
font-weight: bold;
position: absolute;
}
.circle{
background: #ee1d47;
display: inline-block;
width: 30px;
height: 30px;
line-height: 29px;
border-radius: 50%;
color: #fff;
font-weight: bold;
position: absolute;	
z-index: -1;
left:0;
transform-origin: center;
opacity: 1;
animation: ripple 1s ease-out infinite;
}

@keyframes ripple{
from{
	transform: scale(1);
	opacity: 1;
}
to{
	transform: scale(1.7);
	opacity: 0;
}
}

.menu-toltip{
display: inline-block;
position: absolute;
left: 45px;
margin-left: 10px;
}
.menu-toltip a{
color: #333;
text-transform: uppercase;
display: block;
padding: 2px 10px;	
box-shadow: 0 0 1px 2px rgba(0,0,0,0.08);
border: 1px solid #e2e2e2;
border-radius: 4px;
background: #fff;
text-decoration: none;
}

.hover{
color: #fff !important;
background: #ee1d47 !important;
border:1px solid transparent !important;
box-shadow: none !important;
text-decoration: none !important;
}

.menu-toltip .square{
position: absolute;
display: block;
content: " ";
border: 1px solid #e2e2e2;
width: 10px;
height: 10px;
background: #fff;
left: -4px;
top: 40%;
transform: rotate(45deg);
border-top: none;
border-right: none;
box-shadow: -2px 2px 2px rgba(0, 0, 0, 0.1);    
}

.box-toltip .square{
position: absolute;
display: block;
content: " ";
border: 1px solid #e2e2e2;
width: 10px;
height: 10px;
background: #fff;   
transform: rotate(45deg);
top: -5px;
left: 8.5%;
border-top:  1px solid #e2e2e2;
border-right:  none;
border-bottom: none;
border-left:1px solid #e2e2e2;
box-shadow: -2px -2px 10px rgba(0, 0, 0, 0.1);	
}

.box-toltip {

position: absolute;
width: 425px;
height: 86px;
display: inline-block;
color: #333;
border: 1px solid #e2e2e2;
padding: 10px 20px;
text-align: left;
background: #fff;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
top: 50px;
left: 50px;
opacity: 0;
z-index: 3;    
}
.box-toltip-cel{
display: table-cell;
vertical-align: middle;
padding: 5px;
width: 66%;
}
.box-toltip-cel a{
display: inline-block;
padding: 4px 45px;
background: #ee1d47;
color: #fff;
border: none;

font-size: 15px;
transition: all .25s; 
border-radius: 3px;
}

.box-toltip-cel a:hover{
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
}
.box-toltip-cel p{
margin: 0;
font-size: 11px;
line-height: 1.5em;
}
.center{
text-align: center;
}

.posi{
left: 64%;
top: 60%;
}

.right{
left: -339px;
}

.square-left{
left: 355px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dots">
  <span style="margin-left:10px;">1</span>
  <span class="circle"></span>
  <div class="menu-toltip">
<a href="#" class="do">something</a>
<div class="square"></div>

<div class="box-toltip left">
<div class="square"></div>
<div class="box-toltip-cel bloco-left">
  <p>Fusce eu dui. Integer vel nibh sit amet turpis vulputate aliquet. Phasellus id nisi vitae odio pretium aliquam.</p>
</div>
<div class="box-toltip-cel center">
  <a href="#">Link</a>
</div>
  </div>
  </div>
</div>

  • The problem is the mouseleave, which behavior you want the menu to follow?

  • only to make it possible to click on the "Link"

  • Strip the part of the code with mouseleave that will work, now if you have more items like this as a category do a toggle showing the current and hiding the others.

  • I misexpressed myself, when I said "visible" is in the sense of houver, that is active while the cursor is above the element box-toltip, if it leaves the element box-toltip or even of menu-toltip a he hides the box-toltip

  • @Gabrielrodrigues partially corrected, only a problem that when I put the mouse inside the div appearing he redoes the animation some idea?

1 answer

0

I separated the two functions, created a function "hoverIn" and another "hoverOut", put the event on the button to show the "box-toltip" and in the "box-toltip" I put the event to close, so the button will only be responsible for opening the "box-toltip" and the "box-toltip" will be responsible for closing.

Then passing the mouse over the button the "box-toltip" will be shown, and when the mouse leaves the "box-toltip" it will be closed.

function hoverIn(){
    var menuToltip = $(this).closest('.menu-toltip');
		menuToltip.find('a').first().addClass('hover');
		menuToltip.find('.square').first().addClass('hover');
		menuToltip.find('.box-toltip').animate({
			"left":"7px",
			opacity:1
		},300);
}

function hoverOut(){
    var menuToltip = $(this).closest('.menu-toltip');
		menuToltip.find('a').removeClass('hover');
		menuToltip.find('.square').first().removeClass('hover');
		menuToltip.find('.box-toltip').animate({
			"left":"50px",
			opacity:0
		},300);
}

$(function(){
	$('.menu-toltip .do').hover(hoverIn,function(){});
  $('.box-toltip').hover(function(){},hoverOut);
});
.dots{
  background: #ee1d47;
  display: inline-block;
  width: 30px;
  height: 30px;
  line-height: 29px;
  border-radius: 50%;
  color: #fff;
  font-weight: bold;
  position: absolute;
}
.circle{
  background: #ee1d47;
  display: inline-block;
  width: 30px;
  height: 30px;
  line-height: 29px;
  border-radius: 50%;
  color: #fff;
  font-weight: bold;
  position: absolute;	
  z-index: -1;
  left:0;
  transform-origin: center;
  opacity: 1;
  animation: ripple 1s ease-out infinite;
}

@keyframes ripple{
from{
	transform: scale(1);
	opacity: 1;
}
to{
	transform: scale(1.7);
	opacity: 0;
}
}

.menu-toltip{
  display: inline-block;
  position: absolute;
  left: 45px;
  margin-left: 10px;
}
.menu-toltip a{
  color: #333;
  text-transform: uppercase;
  display: block;
  padding: 2px 10px;	
  box-shadow: 0 0 1px 2px rgba(0,0,0,0.08);
  border: 1px solid #e2e2e2;
  border-radius: 4px;
  background: #fff;
  text-decoration: none;
}

.hover{
  color: #fff !important;
  background: #ee1d47 !important;
  border:1px solid transparent !important;
  box-shadow: none !important;
  text-decoration: none !important;
}

.menu-toltip .square{
  position: absolute;
  display: block;
  content: " ";
  border: 1px solid #e2e2e2;
  width: 10px;
  height: 10px;
  background: #fff;
  left: -4px;
  top: 40%;
  transform: rotate(45deg);
  border-top: none;
  border-right: none;
  box-shadow: -2px 2px 2px rgba(0, 0, 0, 0.1);    
}

.box-toltip .square{
  position: absolute;
  display: block;
  content: " ";
  border: 1px solid #e2e2e2;
  width: 10px;
  height: 10px;
  background: #fff;   
  transform: rotate(45deg);
  top: -5px;
  left: 8.5%;
  border-top:  1px solid #e2e2e2;
  border-right:  none;
  border-bottom: none;
  border-left:1px solid #e2e2e2;
  box-shadow: -2px -2px 10px rgba(0, 0, 0, 0.1);	
}

.box-toltip {
  position: absolute;
  width: 425px;
  height: 86px;
  display: inline-block;
  color: #333;
  border: 1px solid #e2e2e2;
  padding: 10px 20px;
  text-align: left;
  background: #fff;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
  top: 50px;
  left: 50px;
  opacity: 0;
  z-index: 3;    
}

.box-toltip-cel{
  display: table-cell;
  vertical-align: middle;
  padding: 5px;
  width: 66%;
}

.box-toltip-cel a{
  display: inline-block;
  padding: 4px 45px;
  background: #ee1d47;
  color: #fff;
  border: none;
  font-size: 15px;
  transition: all .25s; 
  border-radius: 3px;
}

.box-toltip-cel a:hover{
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
}

.box-toltip-cel p{
  margin: 0;
  font-size: 11px;
  line-height: 1.5em;
}

.center{
  text-align: center;
}

.posi{
  left: 64%;
  top: 60%;
}

.right{
  left: -339px;
}

.square-left{
  left: 355px !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="dots">
   <span style="margin-left:10px;">1</span>
   <span class="circle"></span>
   <div class="menu-toltip">
      <a href="#" class="do">something</a>
      <div class="square"></div>
      <div class="box-toltip left">
         <div class="square"></div>
         <div class="box-toltip-cel bloco-left">
            <p>Fusce eu dui. Integer vel nibh sit amet turpis vulputate aliquet. Phasellus id nisi vitae odio pretium aliquam.</p>
         </div>
         <div class="box-toltip-cel center">
            <a href="#">Link</a>
         </div>
      </div>
   </div>
</div>

Browser other questions tagged

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