I need help with displaying a menu that should appear from the right edge of the screen.
Previously, I had a script to show the menu where the user clicked. However, for this specific menu, I adjusted the position by subtracting some pixels from the click coordinates. But I am not satisfied with this approach for two reasons:
- I want the menu to always be displayed at a static distance from the right edge (let's say
10px
) - I don't want to manually calculate the right edge of the screen and subtract the menu width as it may not work well on different devices.
I tried using right: 10;
but it doesn't seem to work as expected. Any suggestions?
$('#cross').on('click', function (e) {
// coordinates to display the menu
var top = e.pageY;
var left = e.pageX;
left = left - 150;
// Display the menu
$("#cross-menu").css({
display: "block",
position: "fixed",
top: "calc(3.5rem)",
left: left
}).addClass("show");
return false;
});