Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. content.css
  2.  
  3. .selection_bubble {
  4. position: absolute;
  5. font-family: arial;
  6. font-size: 1.1em;
  7. background: #a53d38;
  8. color: #fff;
  9. border-radius: 10px;
  10. padding: 20px;
  11. max-width: 400px;
  12. z-index:4;
  13. display: none;
  14. }
  15.  
  16. content.css
  17.  
  18. .selection_bubble {
  19. position: absolute;
  20. font-family: arial;
  21. font-size: 1.1em;
  22. background: #a53d38;
  23. color: #fff;
  24. border-radius: 10px;
  25. padding: 20px;
  26. max-width: 400px;
  27. z-index:4;
  28. display: none;
  29. }
  30.  
  31.  
  32. content.js
  33.  
  34. // Add bubble to the top of the page.
  35. var bubbleDOM = document.createElement('div');
  36. bubbleDOM.setAttribute('class', 'selection_bubble shadow');
  37. document.body.appendChild(bubbleDOM);
  38.  
  39. document.addEventListener('mouseup', function (e) {
  40. var selection = window.getSelection().toString();
  41.  
  42. s = window.getSelection();
  43. oRange = s.getRangeAt(0); //get the text range
  44. oRect = oRange.getBoundingClientRect();
  45.  
  46. renderBubble(e.clientX, e.clientY, 'Loading....');
  47.  
  48. });
  49.  
  50. function renderBubble(mouseX, mouseY, selection) {
  51. var top = window.pageYOffset || document.documentElement.scrollTop,
  52. left = window.pageXOffset || document.documentElement.scrollLeft;
  53.  
  54. bubbleDOM.innerHTML = selection;
  55. bubbleDOM.style.top = top + mouseY - 220 + 'px';
  56. bubbleDOM.style.left = left + mouseX - 140 + 'px';
  57. bubbleDOM.style.display = 'inline-block';
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement