JavaScript mouse events, click the right mouse button, pop-up div simple instance
Document.oncontextmenu = function () {return false}; Disable the right mouse button menu to display
var res = document.getElementById (' box '); Find div
document.body.onmouseup = function (e) { //Click the trigger event in the body (
e.button===2) { // If Button=1 (left mouse button), button=2 (right mouse button), button=0 (Mouse center button)
Console.log (e); The parameters that are passed in are printed out
console.log (e.offsety); Print out the mouse click of the y-axis coordinate
console.log (E.OFFSETX); Print out the mouse click X axis coordinates
res.style.top = e.offsety+ ' px '; When the mouse clicks to the div positioning y-axis
res.style.left = e.offsetx+ ' px '; When the mouse clicks to the div positioning x axis
res.style.display = ' block '; Show Div box
}else{
res.style.display = ' none '; otherwise do not show div box
}
}
Above this JavaScript mouse event, click the right mouse button, pop-up div Simple example is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.