Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. </head>
  8. <body>
  9. <h2>Hello from outside the Shadow DOM!</h2>
  10.  
  11. <!-- This Custom Element will be our Shadow Host and contain the Shadow Root. -->
  12. <my-element></my-element>
  13.  
  14. <!-- This template will hold the implementation for our element. -->
  15. <template id="tmpl">
  16. <style>
  17. h2 {
  18. color: blue;
  19. }
  20. </style>
  21. <h2>Hello from inside the Shadow DOM!</h2>
  22. </template>
  23.  
  24. <!--
  25. Just load the polyfills for Custom Elements, Shady DOM, and Shady CSS.
  26. The Shady CSS polyfill only supports Custom Elements. Since we need
  27. both the Custom Elements and Shady polyfills, may as well load the bundle!
  28. -->
  29. <script src="./node_modules/@webcomponents/webcomponentsjs/webcomponents-sd-ce.js"></script>
  30.  
  31. <script>
  32. // prepareTemplate takes the template and applies the scoping attributes
  33. // to each element and puts styles in the <head>.
  34. ShadyCSS.prepareTemplate(tmpl, 'my-el');
  35. class MyElement extends HTMLElement {
  36. connectedCallback() {
  37. // styleElement enables Custom Properties to work on this element
  38. // and any of its children.
  39. ShadyCSS.styleElement(this);
  40. this.attachShadow({mode: 'open'});
  41. this.shadowRoot.appendChild(tmpl.content.cloneNode(true));
  42. }
  43. }
  44. customElements.define('my-element', MyElement);
  45. </script>
  46.  
  47. </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement