HTML5 Template in Action
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
The
<template>tag holds its content hidden from the client.Content inside a
<template>tag will not be rendered.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 EventsSupport
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的更多相关文章
- [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; ...
- HTML5 template元素
前言 转自http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/ 在单页面应用,我们对页面的无刷新有了更高的要求,H ...
- HTML5 <template>标签元素简介
一.HTML5 template元素初面 <template>元素,基本上可以确定是2013年才出现的.干嘛用的呢,顾名思意,就是用来声明是“模板元素”. 目前,我们在HTML中嵌入模板H ...
- [转]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- ...
- HTML5 Canvas in Action
HTML5 Canvas in Action canvas 图片处理 视频编辑工具 xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
- Web Components & HTML5 & template & slot
Web Components & HTML5 & template & slot https://developer.mozilla.org/en-US/docs/Web/HT ...
- HTML5 <template>
http://www.zhangxinxu.com/wordpress/2014/07/hello-html5-template-tag/
- HTML语义化:HTML5新标签——template
一.前言 当我们使用String-base的模板引擎(如Handlebars.js等)时,要么就通过外部文件存放模板文本,需要时再通过XHR或script标签加载进来:要么通过<script t ...
- HTML5中<template>标签的详细介绍
HTML5中<template>标签的详细介绍(图文) 这篇文章主要介绍了HTML5中的template标签,是HTML5入门中的重要知识,需要的朋友可以参考 一.HTML5 templa ...
随机推荐
- C#高级编程第11版 - 第五章 索引
[1]5.1 泛型概述 1.通过泛型,你可以创建独立于特定类型(contained types)以外的方法和类,而不用为不同类型编写多份同样功能的代码,你只需要创建一个方法或者类. 2.泛型类使用泛型 ...
- Cannot assign requested address问题总结
Cannot assign requested address问题总结 - 简书 https://www.jianshu.com/p/51a953b789a4 python3 server.pyE07 ...
- 序列化 serialize
Serializable 序列化 The byte stream created is platform independent. So, the object serialized on one ...
- Java——序列化与反序列化
序列化 序列化 序列化是什么 如何实现对象序列化 实战练习 Serializable 反序列化 总结 使用Reader读取文件内容1 使用Reader读取文件内容2 序列化是什么? 将对象的状态存储到 ...
- Java 高并发 解决方案
1.HTML静态化 2.图片服务器分离 3.数据库集群和库表散列 4.缓存 5.镜像 6.负载均衡 1)硬件四层交换 2)软件四层交换 一:高并发高负载类网站关注点之数据库 二:高并发高负载网站的系统 ...
- YOLOv1论文解读
摘要 我们提出一种新的目标检测算法--YOLO.以前有关目标检测的研究将检测转化成分类器来执行.然而,我们将目标检测框架化为空间分隔的边界框及相关的类概率的回归问题.在一次评估中,单个神经网络直接从整 ...
- 详解MySQL事务原理
老刘是即将找工作的研究生,自学大数据开发,一路走来,感慨颇深,网上大数据的资料良莠不齐,于是想写一份详细的大数据开发指南.这份指南把大数据的[基础知识][框架分析][源码理解]都用自己的话描述出来,让 ...
- AtCoder Beginner Contest 188 D - Snuke Prime (思维,差分)
题意:你需要订阅一些服务,每个服务每天需要花费\(c_i\),要从第\(a_i\)用到第\(b_i\)天,你可以购买会员,会员每天需要花费\(C\),但是这天的服务不用再另花钱了,问你订阅这些服务的最 ...
- fzu2218 Simple String Problem
Accept: 2 Submit: 16 Time Limit: 2000 mSec Memory Limit : 32768 KB Problem Description Recent ...
- hdu3635 Dragon Balls
Problem Description Five hundred years later, the number of dragon balls will increase unexpectedly, ...