Jump to content
  • 0

Как получить размеры div-а


Terranin
 Share

Question

Задолбался гуглить, все какую-то фигню советуют.

Проблема:

Есть кнопка при нажатии на которую должно выпадать меню, это меню хочется выровнять так чтобы правая граница его совпадала с правой границей кнопки. Для этого нужно получить ширину меню чтобы сдвинуть его влево от кнопки.

Получить ширину не получается ни через menu.offsetWidth ни через menu.style.width , оба эти свойства почему-то возвращают пустое значение. Все остальные функции работают нормально, меню располагается справа от кнопки.

function showMenu(obj, id)
{
if (CurrMenu != null)
CurrMenu.style.display = "none";

var menu = document.getElementById(id);
var width = menu.offsetWidth;
menu.style.left = (getAbsX(obj) - width + 16) + 'px';
menu.style.top = (getAbsY(obj) + 16) + 'px';

//alert(width);

menu.style.display = '';
CurrMenu = menu;
}


<div id="ContextMenu1" style="padding: 5px; border: 1px solid #999999; position: absolute; background: white; display: none; z-index: 100;" onMouseOut="HideMenu()">
<table cellpadding="3">
<tr><td class="MenuItem">Edit record</td></tr>
<tr><td class="MenuItem">Copy key to clipboard</td></tr>
<tr><td class="MenuItem">Copy HardwareID to clipboard</td></tr>
</table>
</div>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy