First of all, you might not want to mix mouseover/mouseout and mouseenter/mouseleave events. They are distinct (for further explanation, refer to this answer). In your case they wouldn't make a lot of difference, but it's always better to follow conventions.
If you want all the textboxes to disappear, all you need to do is listen to the mouseover event on <p>
, and force its parents' siblings' textboxes to disappear, i.e.:
$('p').on('mouseover', function() {
// Show own textbox
$(this).closest('.content').find('.textbox').stop(true, true).fadeIn(1000);
// Hide textbox of parents' siblings
$(this).closest('.content').siblings('.content').find('.textbox').stop(true, true).fadeOut(1000);
});
For a more efficient code, you can store the $(this).closest('.content')
object, i.e.:
$('p').on('mouseover', function() {
// Store parent
var $parent = $(this).closest('.content');
// Show own textbox
$parent.find('.textbox').stop(true, true).fadeIn(1000);
// Hide textbox of parents' siblings
$parent.siblings('.content').find('.textbox').stop(true, true).fadeOut(1000);
});
You may notice that I have included the .stop(true, true)
method before any of the jQuery animations. The reason being that if you do not stop and the animation, it will queue and "bunch up", resulting in a string of delayed animations that do not apparently sync with user action.
See proof-of-concept example below:
//if ($('.vie_writ_que-user_oth').style == display: 'none') {
$('p').on('mouseover', function() {
$(this).closest('.content').find('.textbox').stop(true, true).fadeIn(1000);
$(this).closest('.content').siblings().find('.textbox').stop(true, true).fadeOut(1000);
});
$('.textbox').on('mouseleave', function() {
$(this).stop(true, true).fadeOut(1000);
});
//}
.textbox {
width: 150px;
height: 200px;
border: 1px solid #000;
overflow: auto;
float: left;
display: none;
margin-top: 60px;
}
.content {
float: left position: relative;
}
p.a {
position: absolute;
left: 30px;
}
p.b {
position: absolute;
left: 200px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="content">
<p class="a">hover it</p>
<div class="textbox">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</div>
</div>
<div class="content">
<p class="b">Next hover</p>
<div class="textbox">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
</div>
</div>