Created
March 13, 2019 22:41
-
-
Save InputNeuron/1a097fe5c0b8212a84e83cba8e319773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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