4
I have a menu that opens when I right click on the table.
The problem is that I could not get the mouse position when the page has scroll.
I noticed that you’re taking the Y X based on my monitor, and I need it to take based on the page size.
Someone knows how to fix this?
Follow the code in jsfiddle to make it easy, as I’ve already set the larger page to bug.
document.oncontextmenu = function() {
return false;
};
// Verifica se abre o menu
$("tr").mousedown(function (e) {
// Define a posição do menu
$('.context_menu_pai').css({
"margin-left": e.clientX,
"margin-top": e.clientY
}).show();
// Verifica qual botão clicou
if (e.button === 2) {
$("#menu" + this.id).show();
$(".context_menu_pai:not(#menu" + this.id + ")").hide();
// Adiciona CSS na linha selecionada
$("#" + this.id).addClass('context_menu_select');
} else {
// Fecha menu
$(".context_menu_pai").hide();
}
});
body {
margin: 0;
color: #484848;
font-family: Verdana;
font-size: 13px;
}
.context_menu_pai {
display: none;
position: absolute;
width: 200px;
background: #FFFFFF;
box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
border-radius: 2px;
}
.context_menu {
padding: 12px 8px;
cursor: pointer;
display: block;
color: #484848;
}
.context_menu:hover {
background: #EEEEEE;
}
.text_erro {
color: #F65314;
}
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<div class='context_menu_pai' id='menu2'>
<li class='context_menu'>Editar</li>
<li class='context_menu'>Acessar</li>
<li class='context_menu'>Indicou(0)</li>
<li class='context_menu text_erro'>Bloquear</li>
</div>
<table width="100%" border="1">
<tr id="2">
<td>ID:2</td>
<td>Nome</td>
<td>Idade</td>
</tr>
</table>
Funny if you put the <br> below the table and not the right menu
– Gabriel Rodrigues
yes because it takes the mouse position over the screen size and not over the html size.
– Hugo Borges
Ai when it will show the menu html identifies that in that space there is already an element and does not let perform the overlay
– Gabriel Rodrigues