Skip to content

Instantly share code, notes, and snippets.

@knomdlo
Created August 12, 2018 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knomdlo/28f420106a9b273749e126c34486cbef to your computer and use it in GitHub Desktop.
Save knomdlo/28f420106a9b273749e126c34486cbef to your computer and use it in GitHub Desktop.
<script>
function myfunc(e) {
let ele = document.getElementById('my-dialog');
ele.style["left"] =
(window.innerWidth - e.pageX) < ele.offsetWidth ? e.pageX - ele.offsetWidth : e.pageX;
ele.style["top"] =
(window.innerHeight - e.pageY) < ele.offsetHeight ? e.pageY - ele.offsetHeight : e.pageY;
}
document.onclick = myfunc;
</script>
<body>
<div id="my-dialog" style="position: absolute;width: 100px;
height: 200px;background: grey;">
</div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment