下放是什么意思| 七一年属什么| 绅士是什么意思| 仙姑是什么意思| 什么什么相接| 依非韦伦片治什么病的| 没有美瞳护理液用什么代替| 查血糖挂什么科| 2003属什么| 孩子结膜炎用什么眼药水| abi医学上是什么意思| r值是什么意思| 下午三点是什么时辰| 正高是什么级别| 女人血虚吃什么补最快| 脾大是怎么回事有什么危害| 麻雀吃什么食物| 为什么要流泪| 舌头有裂纹是什么病| 支原体阳性什么意思| 1月13日什么星座| 土豆有什么营养价值| 纳财适合做什么| 流鼻血挂什么科| 十一月二十四是什么星座| 情商是什么| 山西有什么特产| 早上起床腰酸痛是什么原因| 肾囊肿挂什么科| 味美思是什么酒| 真丝乔其纱是什么面料| 灵犀是什么意思| 茔和坟有什么区别| 牙医靠什么吃饭| 岔气吃什么药最管用| 胆囊切除后需要注意什么| 肾阳虚吃什么食物| 什么不惧| 豆汁是什么做的| 舌根苔白厚腻是什么原因| 大云是什么中药| 菠萝蜜的核有什么功效| 平和是什么意思| 云南白药植物长什么样| 喝酒前吃什么药| 为什么家里会有隐翅虫| yrc是什么牌子的鞋| 荷花象征着什么| 育婴员是做什么的| 胎盘低是什么意思| 手机充电发烫是什么原因| 卫生湿巾是干什么用的| 笑死是什么意思| 厚黑学什么意思| 乳头内陷是什么原因| 腰痛看什么科| st-t改变是什么意思| 脚脱皮用什么药| 月季花什么时候开| 口牙是什么意思| 截根疗法是什么| 声东击西是什么意思| 什么地舞动| 半夜两点是什么时辰| 左耳朵发热代表什么预兆| 壶嘴为什么不能对着人| 什么名字最霸气| 豆浆什么时候喝最好| 扪及是什么意思| 灵修是什么意思| 橄榄色是什么颜色| 山的五行属什么| 香椿是什么| 迅速的反义词是什么| 轻断食什么意思| 头发掉什么原因| 2月1号是什么星座| 胆结石可以吃什么水果| 吃什么代谢快有助于减肥| 肛门塞什么东西最舒服| 吃什么食物下奶快而且奶多| fl是什么意思| 点字五行属什么| 儿童干咳吃什么药效果好| 5月6日什么星座| 省公安厅副厅长是什么级别| 农历12月是什么月| 死板是什么意思| 腹痛拉肚子吃什么药| nap是什么意思| 达泊西汀有什么副作用| 撞车了打什么电话| 脱口秀是什么意思| cph是什么意思| 三班两倒是什么意思| 口苦是什么原因引起的| 扁桃体为什么会发炎| 吃什么能让肠道蠕动快| 泡打粉是什么| 乳腺无回声结节是什么意思| 眼袋是什么| 逆钟向转位是什么意思| 经常中暑的人体内缺什么| 印记是什么意思| 结婚需要准备什么| 眼底筛查是检查什么| 什么什么不断| 为什么不建议小孩打流感疫苗| 总打嗝是什么原因| 什么是部首| 血压高吃什么好| dine是什么意思| 夫妻少配无刑是什么意思| 组织机构代码是什么| handmade是什么牌子| 喉结不明显的男生是什么原因| 公因数是什么意思| 脚后跟骨头疼是什么原因| 猴子是什么动物| 青团是什么节日吃的| 什么紫什么红| 爱而不得是什么感觉| 24k黄金是什么意思| 巨细胞病毒igg阳性是什么意思| 降龙十八掌最后一掌叫什么| 纳氏囊肿是什么意思| 奥美拉唑是什么药| 可乐杀精是什么意思| tf卡是什么| 乙醇对人体有什么伤害| a型和o型生的孩子是什么血型| dr是什么意思| 荨麻疹可以吃什么食物| 茵陈有什么功效| 为什么老是抽筋| 六月二十一是什么日子| 甲状旁腺分泌什么激素| 午餐肉炒什么菜好吃| 鞭尸什么意思| x是什么牌子的衣服| 氟苯尼考兽药治什么病| 西瓜为什么叫西瓜| 三十六计第一计是什么计| 五六月份是什么星座| 令是什么生肖| 漫展是什么| 12min是什么意思| 乙肝表面抗体弱阳性是什么意思| 倒签是什么意思| 美国的国鸟是什么| 维生素c什么时候吃效果最好| 复方丹参片治什么病| 梦见大便是什么意思| 移动硬盘什么牌子好| 口腔溃疡吃什么好得快| 1996属鼠的是什么命| 无纺布是什么材料做的| 戒烟后为什么会发胖| 百合与什么搭配最好| h5是什么意思| mri是什么| 单元剧是什么意思| 怀孕16周要做什么检查| 月经刚完同房为什么痛| 为什么分泌物是褐色的| 资治通鉴讲的是什么| 宫寒是什么原因引起的如何调理| 纯阴八字为什么要保密| 脚丫痒是什么原因| 肚脐周围疼痛是什么原因| 认知是什么| 红细胞减少是什么原因| kg是什么意思| 女生右手食指戴戒指什么意思| 舌头上火了吃什么降火| 前列腺肿瘤有什么症状| 经常手麻是什么原因引起的| 肺纤维化有什么症状| 太燃了是什么意思| 尿发黄什么原因| 松茸是什么东西| 什么水解渴| 曼巴是什么意思| LOP是什么胎位| 总是嗳气是什么原因| 空五行属什么| 心肌缺血是什么原因引起的| 市级三好学生有什么用| 班别是什么意思| 苹果什么时候吃最好| 拜谒是什么意思| 部堂大人是什么职位| 殊途同归是什么意思| 软笔是什么| 2039年是什么年| est.是什么意思| 吃盐吃多了有什么危害| 三伏天要注意什么| 膝盖背面叫什么| 祖坟冒青烟是什么意思| 属鸡今年要注意什么| 风湿性心脏病吃什么药| 吃什么排湿气效果好| 俊俏是什么意思| 生长痛是什么| 伶字五行属什么| 梦见拔牙是什么预兆| 低聚异麦芽糖是什么| 腰底部疼痛跟什么病有关| 白化病是什么原因引起的| 什么牌奶粉好| 低密度脂蛋白是什么意思| 右眼上眼皮跳是什么预兆| 了凡四训讲的是什么| 10.31什么星座| 为什么长白头发| 急性心肌炎有什么症状| 流产是什么意思| 西双版纳有什么好玩的地方| 圆明园是什么时候被烧的| 寿终正寝是什么意思| 什么七八什么| 痛点是什么意思| 枸杞泡水喝有什么作用和功效| 肚脐下面是什么部位| 大舌头是什么意思| 经常吃红枣有什么好处和坏处| 痱子长什么样| 低钾会出现什么症状| 3月份是什么季节| get什么意思| 代金券是什么意思| 武汉市长是什么级别| 合疗和医保有什么区别| 脾胃不好有什么症状表现| 户主有什么权利| 低温烫伤是什么意思| lm是什么意思| 什么然泪下| 喝蜂蜜水有什么好处和坏处| 深海鱼油有什么作用| 怀孕了不能吃什么| 淋巴清扫是什么意思| 医学生规培是什么意思| 失眠为什么开奥氮平片| 每天都做梦是什么原因| 林彪为什么叛变| 眼睛一直眨是什么原因| 雪菜是什么菜| 吃什么能减肥最快还能减全身| 春梦是什么| 测血型挂什么科| 圣诞节什么时候| cpu什么意思| 521代表什么含义| 绿色属于五行属什么| 茯苓和土茯苓有什么区别| 工作坊是什么意思| 什么人不能爬泰山| 绿色是什么意思| 每个月月经都提前是什么原因| 什么是心肌炎| 木有什么意思| 狐臭去医院挂什么科| 百度

收购洛阳大华二手PFQ1313反击破(反击式破碎机)

We’re pleased to announce that basic support for the new slot-based shadow DOM API we proposed in April is now available in the nightly builds of WebKit after r190680. Shadow DOM is a part of Web Components, a set of specifications that were initially proposed by Google to enable the creation of reusable widgets and components on the Web. Shadow DOM, in particular, provides a lightweight encapsulation for DOM trees by allowing a creation of a parallel tree on an element called a “shadow tree” that replaces the rendering of the element without modifying the underlying DOM tree. Because a shadow tree is not an ordinary child of the “host” element to which it is attached, users of components cannot accidentally poke into it. Style rules are also scoped, meaning that CSS rules defined outside of a shadow tree do not apply to elements inside the shadow tree and rules defined inside the shadow tree do not apply to elements outside of it.

Style Isolation

One major benefit of using shadow DOM is style isolation. To see how, let’s say we want to create a custom progress bar. We can use two nested div’s to show the bar and another div with the text to show the percentage as follows:

<style>
.progress { position: relative; border: solid 1px #000; padding: 1px; width: 100px; height: 1rem; }
.progress > .bar { background: #9cf; height: 100%; }
.progress > .label { position: absolute; top: 0; left: 0; width: 100%;
    text-align: center; font-size: 0.8rem; line-height: 1.1rem; }
</style>
<template id="progress-bar-template">
    <div class="progress" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
        <div class="bar"></div>
        <div class="label">0%</div>
    </div>
</template>
<script>
function createProgressBar() {
    var fragment = document.getElementById('progress-bar-template').content.cloneNode(true);
    var progressBar = fragment.querySelector('div');
    progressBar.updateProgress = function (newPercentage) {
        this.setAttribute('aria-valuenow', newPercentage);
        this.querySelector('.label').textContent = newPercentage + '%';
        this.querySelector('.bar').style.width = newPercentage + '%';
    }
    return progressBar;
}
</script>

Note the use of the template element, which allows authors to include a snippet of HTML that can be instantiated later by cloning the content. This was the first feature of Web Components we implemented in WebKit that later got merged into the HTML5 specification. A template element can appear anywhere in a document (e.g. between table and tr elements), and content inside template elements is inert and does not run scripts or load images and other types of subresources. Then the user of this custom progress bar can instantiate it and update the progress as follows:

var progressBar = createProgressBar();
container.appendChild(progressBar);
...
progressBar.updateProgress(10);

The problem with this progress bar implementation is that its two internal divs are freely accessible to its users and its style rules are not scoped to the progress bar. For example, the style rules defined for the progress bar will apply to content outside the progress bar with the class name progress:

<section class="project">
    <p class="progress">Pending an approval</p>
</section>

Similarly, style rules defined for other elements could override rules in the progress bar:

<style>
.label { font-weight: bold; }
</style>

While we could work around these problems by using a custom element name such as custom-progressbar to scope rules and then initialize all other properties by all: initial, Shadow DOM provides a much more elegant solution. The idea here is to introduce an encapsulation layer at the outer div so that users of the progress bar don’t see its internals (such as divs created for the label and the bar) and styles defined for the progress bar don’t interfere with the rest of the page and vice versa. To do that, we first create a ShadowRoot on the progress bar by calling attachShadow({mode: 'closed'}), and then append various nodes needed for its implementation under it. Let’s say we’re still using a div to “host” this shadow root, then we can create a new div and attach a shadow root as follows:

<template id="progress-bar-template">
    <style>
        .progress { position: relative; border: solid 1px #000; padding: 1px; width: 100px; height: 1rem; }
        .progress > .bar { background: #9cf; height: 100%; }
        .progress > .label { position: absolute; top: 0; left: 0; width: 100%;
            text-align: center; font-size: 0.8rem; line-height: 1.1rem; }
    </style>
    <div class="progress" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
        <div class="bar"></div>
        <div class="label">0%</div>
    </div>
</template>
<script>
function createProgressBar() {
    var progressBar = document.createElement('div');
    var shadowRoot = progressBar.attachShadow({mode: 'closed'});
    shadowRoot.appendChild(document.getElementById('progress-bar-template').content.cloneNode(true));
    progressBar.updateProgress = function (newPercentage) {
        shadowRoot.querySelector('.progress').setAttribute('aria-valuenow', newPercentage);
        shadowRoot.querySelector('.label').textContent = newPercentage + '%';
        shadowRoot.querySelector('.bar').style.width = newPercentage + '%';
    }
    return progressBar;
}
</script>

Notice that the style element is inside the template element and cloned into the shadow root along with the divs. This allows the style rules defined inside the shadow root to be scoped. Style rules defined outside a shadow root do not apply to elements inside the shadow root either. Tip: while debugging your code, you may find it helpful to use shadow DOM’s open mode so that you can access the newly created shadow root via the shadowRoot property of the host element. e.g. {mode: DEBUG ? 'open' : 'closed'}

Composition with Slots

At this point, you might be wondering why this had to be done in DOM instead of CSS. Styling is a presentational concept, so why should we add new elements to the DOM? In fact, the first public working draft of the CSS Scoping Module Level 1 defines the @scope rule, which enables exactly that. So why did we need to add another mechanism to isolate styles? One motivation was to allow elements used in the implementation of components to be hidden from node traversal APIs such as querySelectorAll and getElementsByTagName. Because nodes inside a shadow root are not found by these APIs by default, users of components that utilize shadow DOM do not need to worry about how each component is implemented. Each component is presented as an opaque element whose implementation details are encapsulated in its shadow DOM. Note that shadow DOM does not provide a cross-origin iframe-like security boundary. Scripts can easily bypass the shadow DOM boundary if needed. Another reason we need a DOM-based solution is for composition. Let’s say we have a list of contacts:

<ul id="contacts">
    <li>
        Commit Queue
        (<a href="mailto:commit-queue@webkit.org">commit-queue@webkit.org</a>)<br>
        One Infinite Loop, Cupertino, CA 95014
    </li>
    <li>
        Niwa, Ryosuke
        (<a href="mailto:rniwa@webkit.org">rniwa@webkit.org</a>)<br>
        Two Infinite Loop, Cupertino, CA 95014
    </li>
</ul>

and we would like to add a fancy UI for each contact’s information in the list when scripts are enabled:

Instead of copying all of this text over to our own shadow DOM, we can use named slots to render the text elsewhere in our shadow DOM without modifying the DOM as follows:

<template id="contact-template">
    <style>
        :host { border: solid 1px #ccc; border-radius: 0.5rem; padding: 0.5rem; margin: 0.5rem; }
        b { display: inline-block; width: 5rem; }
    </style>
    <b>Name</b>: <slot name="fullName"><slot name="firstName"></slot> <slot name="lastName"></slot></slot><br>
    <b>Email</b>: <slot name="email">Unknown</slot><br>
    <b>Address</b>: <slot name="address">Unknown</slot>
</template>
<script>
window.addEventListener('DOMContentLoaded', function () {
    var contacts = document.getElementById('contacts').children;
    var template = document.getElementById('contact-template').content;
    for (var i = 0; i < contacts.length; i++)
        contacts[i].attachShadow({mode: 'closed'}).appendChild(template.cloneNode(true));
});
</script>

Conceptually, slots are holes in a shadow DOM that will be filled by children of its host element. Each element can be assigned into a slot of a specific name by the slot attribute as follows:

<ul id="contacts">
    <li>
        <span slot="fullName">Commit Queue</span>
        (<a slot="email" href="mailto:commit-queue@webkit.org">commit-queue@webkit.org</a>)<br>
        <span slot="address">One Infinite Loop, Cupertino, CA 95014</span>
    </li>
</ul>

Here, we’re attaching a shadow root to the li, and each span with a slot attribute is assigned to the slot of the same name inside the shadow DOM. Let’s take a closer look at the shadow DOM template:

<b>Name</b>:
<slot name="fullName">
    <slot name="firstName"></slot>
    <slot name="lastName"></slot>
</slot><br>
<b>Email</b>: <slot name="email">Unknown</slot><br>
<b>Address</b>: <slot name="address">Unknown</slot>

In this template, we have slots named fullName, which contains two other slots named firstName and lastName, and two additional slots named email and address. The fullName slot is taking the advantage of fallback content, and showing firstName and lastName only if there were no nodes assigned to the fullName slot. Even though there is exactly one node assigned to each slot in this example, multiple elements with the same slot attribute value can be assigned to a single slot, and they will appear in the order they appeared as the children of the host element. You can also use an unnamed default slot that will be filled by all of the host’s children that don’t have a slot attribute specified. When a Web browser renders this content, the content of the li element is replaced by the shadow DOM, and slots inside of it are replaced by their assigned node as if rendering the following DOM instead:

<ul id="contacts">
    <li>
        <!--shadow-root-start-->
            <b>Name</b>:
            <slot name="fullName">
                <!--slot-content-start-->
                    <span slot="fullName">Commit Queue</span>
                <!--slot-content-end-->
            </slot><br>
            <b>Email</b>:
            <slot name="email">
                <!--slot-content-start-->
                    <a slot="email" href="mailto:commit-queue@webkit.org">commit-queue@webkit.org</a>
                <!--slot-content-end-->
            </slot><br>
            <b>Address</b>:
            <slot name="address">
                <!--slot-content-start-->
                    <span slot="address">One Infinite Loop, Cupertino, CA 95014</span>
                <!--slot-content-end-->
            </slot>
        <!--shadow-root-end-->
    </li>
</ul>

As you can see, slot-based composition is a powerful tool that allows widgets to pull in the page content without cloning or modifying the DOM. With it, widgets can respond to changes made to its child nodes without MutationObservers or an explicit notification via script. In essence, composition turns the DOM into a communication medium between components.

Styling the Host Element

There is one more thing to note in the previous example, which had a mysterious pseudo-class :host:

<template id="contact-template">
    <style>
        :host { border: solid 1px #ccc; border-radius: 0.5rem; padding: 0.5rem; margin: 0.5rem; }
        b { display: inline-block; width: 5rem; }
    </style>
...
</template>

This pseudo class, as its name suggests, matches the host element of the shadow DOM in which this rule appears. By default, author style rules defined outside the shadow DOM have a higher precedence over rules defined in the shadow DOM. This allows a component to define its “default style”, and let users of the component override as needed. In addition, a component can use !important to force a certain style, such as width and display type, without which it cannot function properly with. Any !important rules defined inside a shadow DOM have a higher precedence over regular and !important rules defined outside the shadow DOM.

Future Work

There is still a lot of work left for Web Components. For styling, we would like to allow styling nodes assigned to a slot inside a shadow DOM. There is also a desire for components to respond to the document theme as well as exposing a stylable part to their users like CSS pseudo elements. In the longer term, we would like to see an imperative DOM API to manipulate slot assignments as we proposed a while ago. To complement shadow DOM, we’re also interested in custom elements. The custom elements API allows authors to associate a JavaScript class with a particular element name in HTML documents, and it’s a great way to attach shadow DOM and other custom behaviors idiomatically. Unfortunately, there are a few conflicting proposals on when and how to create a custom element. To help steer the discussion in W3C, we’re planning to prototype it in WebKit. For packaging and delivering Web Components, we’ve been working on ES6 modules. Like Mozilla, we believe modules will radically change the way authors strcuture their pages. We would also like to eventually design an API to create a fully isolated web component with an iframe-like security boundary on top of shadow DOM and custom elements. To conclude, we’re really excited about bringing a major feature of Web Components to WebKit, and we’ll keep you posted about more features coming your way. If you have any questions, please feel free to contact myself, @WebKit, or Jon Davis.

关节炎吃什么药好得快 结肠炎吃什么药治疗效果好 便秘吃什么药快速排便 布洛芬什么时候起效 巽是什么意思
独代表什么生肖 东北和山东有什么区别 检查肝肾功能挂什么科 高大尚是什么意思 1954年属什么生肖
手抖是什么病的前兆 去疤痕挂什么科 做不好的梦预示着什么 心跳加速心慌吃什么药 银耳和什么一起煮最好
阳虚是什么 社保断了有什么影响 聋哑人为什么不会说话 上午10点半是什么时辰 依靠是什么意思
胃炎吃什么消炎药hcv8jop3ns5r.cn 指南针为什么不叫指北针hcv9jop2ns4r.cn 头发沙发是什么意思hcv8jop7ns7r.cn 腹腔积液是什么原因hcv8jop1ns0r.cn 治愈是什么意思hcv7jop9ns4r.cn
躯体是什么意思hcv8jop1ns5r.cn 在什么情况下需要做肠镜hcv9jop7ns0r.cn 公务员是做什么工作的zhongyiyatai.com 螃蟹吃什么东西hcv9jop1ns0r.cn 刀鱼和带鱼有什么区别hcv8jop7ns0r.cn
神经病是什么意思hcv8jop5ns1r.cn 匹诺曹什么意思hcv7jop9ns3r.cn 海参不适合什么人吃hcv8jop8ns8r.cn 放下是什么意思creativexi.com 进产房吃什么补充体力hcv9jop0ns8r.cn
便血挂什么科sscsqa.com 震慑是什么意思chuanglingweilai.com 山竹不能和什么水果一起吃wuhaiwuya.com 老鸨是什么hcv7jop5ns4r.cn 胆红素阴性是什么意思hcv8jop6ns3r.cn
百度