HTML5 Template in Action

https://developer.mozilla.org/es/docs/Web/HTML/Elemento/template

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/template

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5

https://developer.mozilla.org/en-US/docs/Web/CSS/@import

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

https://www.html5rocks.com/zh/tutorials/webcomponents/template/


"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);
}; 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);
}
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");
}

blogs

https://www.w3schools.com/html/html5_intro.asp

https://www.w3schools.com/tags/tag_template.asp

  1. The <template> tag holds its content hidden from the client.

  2. Content inside a <template> tag will not be rendered.

  3. The content can be visible and rendered later by using JavaScript.

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_template2


<button onclick="showContent()">Show template</button> <template>
  <h2>Flower</h2>
  <img src="https://www.w3schools.com/tags/img_white_flower.jpg" width="214" height="204">
</template>

const showContent = () => {
let temp = document.getElementsByTagName("template")[0],
clone = temp.content.cloneNode(true);
document.body.appendChild(clone);
};

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_template3


SSE: Server-Sent Event

https://www.w3schools.com/html/html5_serversentevents.asp

EventSource

Check Server-Sent Events Support

Create a new EventSource object, and specify the URL of the page sending the updates


if(typeof(EventSource) !== "undefined") {
// Yes! Server-sent events support!
var source = new EventSource("demo_sse.php");
source.onmessage = function(event) {
document.getElementById("result").innerHTML += event.data + "<br>";
};
} else {
// Sorry! No server-sent events support..
}

text/event-stream

Server-Side Code Example

For the example above to work, you need a server capable of sending data updates (like PHP or ASP).

The server-side event stream syntax is simple. Set the "Content-Type" header to "text/event-stream". Now you can start sending event streams.


<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache'); $time = date('r');
echo "data: The server time is: {$time}\n\n";
flush(); ?>

https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_sse



"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.querySelector(`[data-tempalte="tempalte-img"]`);
let temp = document.getElementsByTagName("template")[0],
clone = temp.content.cloneNode(true);
document.body.appendChild(clone);
}; const templateGenerator = (datas = [], debug = false) => {
let result = ``;
// do something...
//get the template element:
let temp = document.getElementsByTagName("template")[1];
// let temp = document.querySelector(`[data-tempalte="tempalte-links"]`);
//get the DIV element from the template:
let item = temp.content.querySelector("div");
//for each item in the array:
for (let i = 0; i < datas.length; i++) {
//Create a new node, based on the template:
let a = document.importNode(item, true);
//Add data from the array:
a.textContent += datas[i];
//append the new node wherever you like:
document.body.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");
}

responsive-html5-web-templates

https://www.mockplus.com/blog/post/free-responsive-html5-web-design-templates

https://colorlib.com/wp/free-business-website-templates/

HTML5 Template in Action的更多相关文章

  1. [MODx] 1. Add Html5 template into the MODx

    1. Connet MODx by SSH: Go to the MODx cloud; Find you current user and right click selet Edit Cloud; ...

  2. HTML5 template元素

    前言 转自http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/ 在单页面应用,我们对页面的无刷新有了更高的要求,H ...

  3. HTML5 <template>标签元素简介

    一.HTML5 template元素初面 <template>元素,基本上可以确定是2013年才出现的.干嘛用的呢,顾名思意,就是用来声明是“模板元素”. 目前,我们在HTML中嵌入模板H ...

  4. [转]HTML5 Day 4: Add Drop Down Menu to ASP.NET MVC HTML5 Template using CSS and jQuery

    本文转自:http://pietschsoft.com/post/2010/11/17/HTML5-Day-4-Add-DropDown-Menu-ASPNET-MVC-HTML5-Template- ...

  5. HTML5 Canvas in Action

    HTML5 Canvas in Action canvas 图片处理 视频编辑工具 xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

  6. Web Components & HTML5 & template & slot

    Web Components & HTML5 & template & slot https://developer.mozilla.org/en-US/docs/Web/HT ...

  7. HTML5 <template>

    http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/

  8. HTML语义化:HTML5新标签——template

    一.前言 当我们使用String-base的模板引擎(如Handlebars.js等)时,要么就通过外部文件存放模板文本,需要时再通过XHR或script标签加载进来:要么通过<script t ...

  9. HTML5中<template>标签的详细介绍

    HTML5中<template>标签的详细介绍(图文) 这篇文章主要介绍了HTML5中的template标签,是HTML5入门中的重要知识,需要的朋友可以参考 一.HTML5 templa ...

随机推荐

  1. Linux系统设置 SSH 通过密钥登录

    我们一般使用 PuTTY 等 SSH 客户端来远程管理 Linux 服务器.但是,一般的密码方式登录,容易有密码被暴力破解的问题.所以,一般我们会将 SSH 的端口设置为默认的 22 以外的端口,或者 ...

  2. Bitter.Core系列四:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之 示例 查询

    一: 单表模型驱动查询 如下示例代码演示: // 根据ID 查询: var studentquery = db.FindQuery<TStudentInfo>().QueryById(12 ...

  3. 日志采集技术分析 Inode Inotify

    日志采集技术分析[阿里] - 新手学习导向 - 中国红客联盟 - Powered by HUC http://www.cnhonkerarmy.com/thread-236973-1-1.html

  4. 消息中间件——rocketmq环境配置

    产生原因 RocketMQ概述 RocketMQ 是一款分布式.队列模型的消息中间件,具有以下特点: 能够保证严格的消息顺序 提供丰富的消息拉取模式 高效的订阅者水平扩展能力 实时的消息订阅机制 亿级 ...

  5. Centos6.5添加163软件yum源

    将yum源设置为163yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本无法找到.具体设置方法如下: 1,进入yum源配置目录cd /etc/yum.repos.d 2,备份系统自带的y ...

  6. OSPF特殊区域和LSA

    OSPF路由计算优选次序: (1) 直连路由:本路由器发起的LSA 1.2: (2) 区域内路由:O: LSA 1.2: (3) 区域间路由:O IA: LSA 3: (4) 1类外部路由:O E1: ...

  7. spring源码学习笔记之容器的基本实现(一)

    前言 最近学习了<<Spring源码深度解析>>受益匪浅,本博客是对学习内容的一个总结.分享,方便日后自己复习或与一同学习的小伙伴一起探讨之用. 建议与源码配合使用,效果更嘉, ...

  8. 入坑wsl

    用了一个月的mac os, 又回归windows了, mac确实好看, 终端配合iterm2也很舒服, 奈何终究我们不合适...生态毕竟没有windows那么丰富; 切回windows最无法忍受的就是 ...

  9. 理解了这三点,才敢说自己会写Python代码

    某同学应聘Python岗位被录用.上班第一天,Leader吩咐他写一个获取次日日期信息的函数.该同学信心满满地写下了这样一段代码, 然后就没有然后了. import time def get_next ...

  10. 2. Linear Regression with One Variable

    Speaker:Andrew Ng 这一次主要讲解的是单变量的线性回归问题. 1.Model Representation 先来一个现实生活中的例子,这里的例子是房子尺寸和房价的模型关系表达. 通过学 ...