1
Well, with the help of some people here in the stack I am modifying my tooltip system, it is almost ready, however I am having a problem.
When I use a very large text in the class 'masterTooltip-left' the tooltip bug, it does not align right and therefore is not displayed. someone knows how to solve this?
$(document).ready(function() {
$('.masterTooltip-right').hover(function() {
var title = $(this).attr('title');
$(this).data('tipText', title).removeAttr('title');
$('<p class="tooltip-right"></p>').html(title).appendTo('body').fadeIn('fast');
}, function() {
$(this).attr('title', $(this).data('tipText'));
$('.tooltip-right').hide();
}).mousemove(function(e) {
// Posição
var mousex = e.pageX + 25;
var mousey = e.pageY + -25;
$('.tooltip-right').css({
top: mousey,
left: mousex
});
});
$('.masterTooltip-left').hover(function() {
var title = $(this).attr('title');
$(this).data('tipText', title).removeAttr('title');
$('<p class="tooltip-left"></p>').html(title).appendTo('body').fadeIn('fast');
}, function() {
$(this).attr('title', $(this).data('tipText'));
$('.tooltip-left').hide();
}).mousemove(function(e) {
// Posição
var mousex = e.pageX - 150;
var mousey = e.pageY + -25;
$('.tooltip-left').css({
top: mousey,
left: mousex
});
});
});
.tooltip-right, .tooltip-left {
display: none;
position: absolute;
border: 1px solid #616161;
background-color: #323232;
border-radius: 4px;
padding: 10px;
color: #FFFFFF;
}
.tooltip-right::after {
position: absolute;
content: '';
left: -20px;
top: 3px;
border: 10px solid transparent;
border-right-color: #323232;
}
.tooltip-left:after {
position: absolute;
content: '';
right: -10px;
top: 3px;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
border-left: 10px solid #323232;
}
.right {
float: right;
}
.w100 {
width: 100px;
background-color: #0091FF;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div class='masterTooltip-right w100' title="erro">MOUSE</div>
<div class='masterTooltip-left right w100' title="TEXTO AQUI">MOUSE</div>
<br><br><br>
<div class='masterTooltip-left right w100' title="sssssssssssssssssssss">BUG</div>
the bug is that the tooltip is "disappearing and appearing"? if it is, the simplest way to solve this is instead of you positioning the tooltip on the screen, put the tooltip as the child of the element that fired. so the "mouseout" will not happen if the mouse enters the tooltip.
– William Bruno Rocha Moraes
He keeps disappearing because he’s not in the right position. tooltip-right works, tooltip-left does not, because when the text is large it is not within 10px of the cursor. get it? the structure I do not want to move, so it is very simple
– Hugo Borges
so that’s exactly what I said.. actually it some pq the cursor enters inside the tooltip and this makes it exit the shooting element, so it closes.
– William Bruno Rocha Moraes
um, would you change the code I posted with your solution?
– Hugo Borges