Я пытаюсь сделать пользовательское контекстное меню. В конце концов я введу все варианты.
Я попробовал это как в Firefox, так и в Chrome, и это даже не появляется. Он просто показывает контекстное меню по умолчанию.
Вот мой код: < /p>
sandbox.html:образной />
Sandbox
This is the context menu div.
Put all your context menu-y things in here.
< /code>
sandbox.css:
/* CSS for Christian's Sandbox */
#contextmenu {
display: none;
position: absolute;
left: 0px;
top: 0px;
border: 1px solid #aaa;
border-radius: 2px;
background-color: #ccc;
color: #000;
}
< /code>
sandbox.js:
/* JavaScript for Christian's Sandbox */
document.onload = function() { // Make sure this all works
// Context menu script
var contextmenudiv = document.getElementById("contextmenu"),
contextmenu = {
hide: function(event) {
// Hide the context menu div
contextmenudiv.style.display = "none";
// Remove the event listener
document.removeEventListener("click", contextmenu.hide, true);
},
};
document.addEventListener("contextmenu", function(event) {
// Prevent the browser from opening the default context menu
event.preventDefault();
// Move the context menu to where the mouse is with respect to the page
contextmenudiv.style.left = (event.pageX + scrollX) + "px";
contextmenudiv.style.top = (event.pageY + scrollY) + "px";
// Display it
contextmenudiv.style.display = "block ";
// When you click somewhere else, hide it
document.addEventListener("click", contextmenu.hide, true);
}, true);
}
Подробнее здесь: https://stackoverflow.com/questions/924 ... -wont-work
Пользовательский контекстный меню HTML/JavaScript не будет работать ⇐ Html
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Меню настройки основного меню не обновляется в меню «Настройки» меню паузы
Anonymous » » в форуме C# - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-