-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.html
147 lines (121 loc) · 4.1 KB
/
test1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test1</title>
<style>
my-element {
/* overrides default */
width: 50vw;
height: 30vh;
border: 4px solid green;
/* doesn't work
::-webkit-scrollbar {
block-size: 1rem;
}
::-webkit-scrollbar-track {
background-color: black
}
::-webkit-scrollbar-thumb {
background-color: red;
} */
}
p {
border: 4px solid red;
width: 75vw;
}
/* Both work, one in my-element, the other everywhere */
/* my-element::-webkit-scrollbar {
block-size: 1rem;
}
my-element::-webkit-scrollbar-track {
background-color: black
}
my-element::-webkit-scrollbar-thumb {
background-color: red;
} */
/* ::-webkit-scrollbar {
block-size: 1rem;
}
::-webkit-scrollbar-track {
background-color: black
}
::-webkit-scrollbar-thumb {
background-color: red;
} */
</style>
</head>
<body>
<script>
customElements.define(
'my-element',
class extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' })
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
overflow: scroll;
}
</style>
<slot></slot>
`
console.log('host', this.shadowRoot.host)
}
}
)
</script>
<my-element>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Totam iste esse eum molestias dolore fuga cupiditate! Ducimus est omnis ipsum aperiam, esse beatae dolorum repudiandae veritatis delectus labore dignissimos ratione!
</p>
<p>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Totam iste esse eum molestias dolore fuga cupiditate! Ducimus est omnis ipsum aperiam, esse beatae dolorum repudiandae veritatis delectus labore dignissimos ratione!
</p>
<p>
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Vitae sunt vel dignissimos mollitia explicabo? Praesentium tempore nesciunt possimus non ex. Fugit, distinctio! Animi magni debitis totam est neque quia et?
</p>
</my-element>
<script>
const typeOf = obj =>
({}.toString
.call(obj)
.match(/\s(\w+)/)[1]
.toLowerCase())
console.log(document.querySelectorAll('my-element p').length); // 3
console.log(document.querySelector('my-element'));
const el = document.querySelector('my-element')
console.log(el.shadowRoot);
console.log(typeOf(el));
</script>
</body>
</html>
<!--
::slotted(*) {
}
// alert(this.innerHTML); // empty (*)
// setTimeout(() => alert(this.innerHTML)); // John (*)
// constructor() {
// super()
// this.attachShadow({ mode: 'open' })
// }
// connectedCallback() {
// // console.log('connectedCallback');
// alert(this.innerHTML)
// setTimeout(() => alert(this.innerHTML))
// this.shadowRoot.innerHTML = `
// <style>
// :host {
// width: 20rem;
// height: 20rem;
// }
//
</style>
// `
// }
<my-element name="foo" id="mine">
constructor() {
super()
// this.attachShadow({ mode: 'open' })
}
-->