Skip to content

Instantly share code, notes, and snippets.

@InputNeuron
Created March 13, 2019 22:41
Show Gist options
  • Select an option

  • Save InputNeuron/1a097fe5c0b8212a84e83cba8e319773 to your computer and use it in GitHub Desktop.

Select an option

Save InputNeuron/1a097fe5c0b8212a84e83cba8e319773 to your computer and use it in GitHub Desktop.
<html>
<head>
<style>
#child0 {
position: absolute;
left: 50px;
top: 50px;
}
#child1 {
position: absolute;
left: 150px;
top: 150px;
}
</style>
</head>
<body>
<div id="parent">
<div id="child0">
this is content in the child
</div>
<div id="child1">
this is content in a second child.
</div>
</div>
<script>
let target = document.querySelector('html');
// parent.addEventListener('mouseover',() => {
// event.preventDefault();
// });
parent.addEventListener('mousemove',(event) => {
// if the selection is active... and the target is NOT a child div then
// cancel the mouse operation.
const range = window.getSelection().getRangeAt(0);
if (event.target.parentElement.id !== 'parent') {
if (! range.collapsed) {
event.preventDefault();
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment