I'm putting together a Tooltip using jquery. It is 100% working, the problem is that when I put it on the right side of the monitor it does not appear. How do I make it identify if it has space? And if it does not have it open it on the left side.
Keep it running:
$(document).ready(function() {
$('.masterTooltip').hover(function() {
var title = $(this).attr('title');
$(this).data('tipText', title).removeAttr('title');
$('<p class="tooltip"></p>').html(title).appendTo('body').fadeIn('fast');
}, function() {
$(this).attr('title', $(this).data('tipText'));
$('.tooltip').hide();
}).mousemove(function(e) {
// Get X Y coordinates
var mousex = e.pageX + 25;
var mousey = e.pageY + -25;
$('.tooltip').css({
top: mousey,
left: mousex
});
});
});
.tooltip {
display: none;
position: absolute;
border: 1px solid #616161;
background-color: #323232;
border-radius: 4px;
padding: 10px;
color: #FFFFFF;
}
.tooltip::after {
position: absolute;
content: '';
left: -20px;
top: 3px;
border: 10px solid transparent;
border-right-color: #323232;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><divclass='masterTooltip'title="TEXTO AQUI">MOUSE</DIV>