zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    HTML Imports

    https://www.w3.org/TR/html-imports/

    index.html

    
    <!DOCTYPE html>
    <html lang="zh-Hans">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Web Component & HTML imports</title>
    </head>
    
    <body>
        <section>
            <h1>Web Component & HTML imports</h1>
        </section>
        <section data-modules="template-container">
            <!-- css -->
            <link rel="stylesheet" href="./tempalte.css">
            <!-- template -->
            <link rel="import" href="./template.html">
            <section data-template="container">
                <!-- templates -->
            </section>
            <section data-html="container">
                <!-- html -->
            </section>
            <!--js-->
        </section>
        <script>
            const supportsImports = () => {
                return "import" in document.createElement("link");
            };
            if (supportsImports()) {
                // Good to go!
                let templatesBox = document.querySelector(`[data-template="container"]`),
                    link = document.querySelector(`link[rel=import]`),
                    template = link.import, // #document
                    html = template.querySelector(`html`);
                // Access DOM of the document in /imports/template.html
                templatesBox.appendChild(html);
                let section = document.querySelector(`section[data-modules="template-container"]`),
                    script = document.createElement("script");
                script.src = "./tempalte.js";
                section.insertAdjacentElement(`beforeend`, script);
                /*
                     let link = document.createElement("link");
                    link.rel = "import";
                    link.href = "template.html";
                    link.setAttribute("async", "");
                    // make it async!
                    link.onload = function(e) {
                        //...
                    };
                    link.onerror = function(e) {
                        //...
                    };
                    document.head.appendChild(link);
                */
            } else {
                // Use other libraries/require systems to load files.
            }
        </script>
    </body>
    
    </html>
    
    

    template.html

    
    <!-- csss -->
    <!-- <link rel="stylesheet" href="./tempalte.css"> -->
    <!-- template -->
    <template data-tempalte="tempalte-img">
        <h3>Flower Image</h3>
        <img src="https://www.w3schools.com/tags/img_white_flower.jpg">
    </template>
    <template data-tempalte="tempalte-links">
        <h3>links</h3>
        <div data-class="links">I like: </div>
    </template>
    <!-- js -->
    <!-- <script src="./tempalte.js"></script> -->
    
    

    template.js

    
    "use strict";
    
    /**
     *
     * @author xgqfrms
     * @license MIT
     * @copyright xgqfrms
     * @description HTML5 Template
     * @augments
     * @example
     *
     */
    
    /*
    
    <template>
        <h2>Flower</h2>
        <img src="https://www.w3schools.com/tags/img_white_flower.jpg">
    </template>
    
    
    <template>
        <div class="myClass">I like: </div>
    </template>
    
    */
    
    const showContent = () => {
        // let temp = document.getElementsByTagName("template")[0],
        let temp = document.querySelector(`[data-tempalte="tempalte-img"]`),
            clone = temp.content.cloneNode(true);
        // document.body.appendChild(clone);
        let box = document.querySelector(`[data-html="container"]`);
            box.appendChild(clone);
    };
    
    const templateGenerator = (datas = [], debug = false) => {
        let result = ``;
        // let temp = document.getElementsByTagName("template")[1],
        let temp = document.querySelector(`[data-tempalte="tempalte-links"]`),
            item = temp.content.querySelector("div");
        for (let i = 0; i < datas.length; i++) {
            let a = document.importNode(item, true);
            a.textContent += datas[i];
            // document.body.appendChild(a);
            let box = document.querySelector(`[data-html="container"]`);
            box.appendChild(a);
        }
        return result;
    };
    
    const arr = ["Audi", "BMW", "Ford", "Honda", "Jaguar", "Nissan"];
    
    if (document.createElement("template").content) {
        console.log("YES! The browser supports the template element");
        templateGenerator(arr);
        setTimeout(() => {
            showContent();
        }, 0);
    } else {
        console.error("No! The browser does not support the template element");
    }
    
    
    
    

    template.css

    
    @charset "UTf-8";
    
    /* test.css */
    
    :root {
        --cololr: #000;
        --default-cololr: #fff;
        --new-cololr: #0f0;
    }
    
    [data-class="links"] {
        color: white;
        background-color: DodgerBlue;
        padding: 20px;
        text-align: center;
        margin: 10px;
    }
    
    

    https://www.html5rocks.com/en/tutorials/webcomponents/imports/

    http://blog.teamtreehouse.com/introduction-html-imports

    https://github.com/webcomponents/html-imports

    web components

    https://www.webcomponents.org

    https://www.webcomponents.org/polyfills/

    https://github.com/webcomponents/webcomponentsjs

    https://github.com/webcomponents/custom-elements


    Web Component & HTML imports

    https://cdn.xgqfrms.xyz/HTML-imports/templates/index.html

    https://github.com/webcomponents/html-imports/issue

    removed (2020.07.01)

    https://caniuse.com/#search=html imports


    Flag Counter

    ©xgqfrms 2012-2020

    www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


  • 相关阅读:
    使用可跨平台的函数执行命令
    linux查看及修改文件权限以及相关
    php 文件缓存类
    秒杀抢购思路以及高并发下数据安全
    php 无限分类
    isset ,empty,is_null 区别
    phpstorm 在线激活码
    phpstorm 不能提示代码tp 3.2 $this->display等 解决办法
    laravel-ide-helper 遇到There are no commands defined问题怎么解决
    NFS共享服务
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/9103360.html
Copyright © 2011-2022 走看看