Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4.  
  5. #child0 {
  6. position: absolute;
  7. left: 50px;
  8. top: 50px;
  9. }
  10.  
  11. #child1 {
  12. position: absolute;
  13. left: 150px;
  14. top: 150px;
  15. }
  16. </style>
  17.  
  18. </head>
  19.  
  20. <body>
  21.  
  22. <div id="parent">
  23.  
  24. <div id="child0">
  25. this is content in the child
  26. </div>
  27.  
  28.  
  29. <div id="child1">
  30. this is content in a second child.
  31. </div>
  32.  
  33. </div>
  34.  
  35. <script>
  36.  
  37. let target = document.querySelector('html');
  38.  
  39. // parent.addEventListener('mouseover',() => {
  40. // event.preventDefault();
  41. // });
  42.  
  43. parent.addEventListener('mousemove',(event) => {
  44.  
  45. // if the selection is active... and the target is NOT a child div then
  46. // cancel the mouse operation.
  47.  
  48. const range = window.getSelection().getRangeAt(0);
  49.  
  50. if (event.target.parentElement.id !== 'parent') {
  51.  
  52. if (! range.collapsed) {
  53. event.preventDefault();
  54. }
  55.  
  56. }
  57.  
  58. });
  59.  
  60. </script>
  61.  
  62.  
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement