I'm creating a simple notification div which appears when I press one of buttons and then disappears by itself:
I can create a div dynamically which is in the center of the screen by clicking on one of the buttons:
var el = document.createElement("div");
el.setAttribute("style","position:absolute;top:50%;left:50%;background-color:white;");
el.innerHTML = msg;
document.body.appendChild(el);
The problem is, when I scroll down a page and click on another button, the div appears outside of visible area. How can I create it in the center of the screen no matter if the page is scrolled down or up? It should always appear in the center of the screen where it can be seen.