I'm learning JavaScript and jQuery and while doing the following exercise I had a problem. I have a div on the right side of the page which contains another smaller div, which contains an unordered list with some imgs, that I want to appear only when the mouse pointer enters the first div.
The problem is that when the mouse pointer enters the first div, the smaller one starts moving up and down uncontrollably.
I've tried using the .is(:hover) method on the bigger div, as suggested by another question on SO but it didn't help.
Here's my code:
stato = "out";
$("#control").mouseover(
function() {
if (stato == "out")
$("#socialBox").animate({
top: 300
});
//$("#socialBox").show();
stato = "in";
}
);
$("#control").mouseleave(
function() {
$("#socialBox").animate({
top: -500
});
//$("#socialBox").hide();
stato = "out";
}
);
body {
background: lightblue;
}
img {
height: 50px;
width: 50px;
}
ul {
list-style-type: none;
}
#control {
position: fixed;
right: 0px;
top: 0px;
height: 100%;
width: 100px;
background: yellow;
}
#socialBox {
position: fixed;
top: -500px;
right: 0px;
width: 75px;
background: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="control"></div>
<div id="socialBox">
<ul>
<li><img id="cane" src="img/cane.jpg" /></li>
<li><img id="gatto" src="img/gatto.jpg" /></li>
<li><img id="koala" src="img/koala.jpg" /></li>
<li><img id="mucca" src="img/mucca.jpg" /></li>
<li><img id="panda" src="img/panda.jpg" /></li>
<li id="nascondi"> X </li>
</ul>
</div>
I've also tried using other mouse events such as mouseenter and mouseout but I get the same issue.
Thanks in advance.