Нет описания

parent-through-assigned-slot.html 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html> <title>Basic Visual Test</title>
  2. <style>
  3. @import '/reset.css';
  4. #reference {
  5. width: 200px;
  6. height: 200px;
  7. background-color: red;
  8. box-shadow: inset 0 0 0 1px black;
  9. }
  10. #popper {
  11. width: 100px;
  12. height: 100px;
  13. background-color: rebeccapurple;
  14. box-shadow: inset 0 0 0 1px black;
  15. }
  16. </style>
  17. <parent-element id="scroll">
  18. <div id="reference">Reference Box</div>
  19. </parent-element>
  20. <div id="popper">Popper Box</div>
  21. <script type="module">
  22. class ParentElement extends HTMLElement {
  23. constructor() {
  24. super();
  25. this.attachShadow({ mode: 'open' });
  26. this.shadowRoot.innerHTML = this.template;
  27. this.scrollParent = this.shadowRoot.querySelector('#scroll');
  28. }
  29. get scrollTop() {
  30. return this.scrollParent.scrollTop;
  31. }
  32. set scrollTop(top) {
  33. this.scrollParent.scrollTop = top;
  34. }
  35. get template() {
  36. return `
  37. <style>
  38. @import '/reset.css';
  39. :host {
  40. display: block;
  41. }
  42. #scroll {
  43. overflow: scroll;
  44. width: 300px;
  45. height: 300px;
  46. background-color: grey;
  47. }
  48. #scroll::before {
  49. content: 'before';
  50. display: block;
  51. height: 300px;
  52. width: 1px;
  53. }
  54. #scroll::after {
  55. content: 'after';
  56. display: block;
  57. height: 300px;
  58. width: 1px;
  59. }
  60. </style>
  61. <div id="scroll">
  62. <slot></slot>
  63. </div>
  64. `;
  65. }
  66. }
  67. customElements.define('parent-element', ParentElement);
  68. </script>
  69. <script type="module">
  70. import { createPopper } from '../dist/popper.js';
  71. const reference = document.querySelector('#reference');
  72. const popper = document.querySelector('#popper');
  73. window.instance = createPopper(reference, popper, {
  74. placement: 'right',
  75. });
  76. </script>