21|21|新兴API
01|requestAnimationFrame
(function(){
function draw(timestamp){
// 计算两次重绘的时间间隔
let drawStart = (timestamp || Date.now()),
diff = drawStart - startTime;
// 使用diff确定下一步的绘制时间// 把startTime重写为这一次的绘制时间
startTime = drawStart;
// 重绘UI
requestAnimationFrame(draw);
}let requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame,
startTime = window.mozAnimationStartTime || Date.now();
requestAnimationFrame(draw);
})();
02|File API
//通过监听change事件并读取files集合,就可以知道每个文件信息
fileList.addEventListener("change", function(event){
var files = event.target.files,
i=0,
len = files.length;
while(i";
i++;
}
output.innerHTML = info;
}
}
EventUtil.addHandler(droptarget, "dragenter", handleEvent);
EventUtil.addHandler(droptarget, "dragover", handleEvent);
EventUtil.addHandler(droptarget, "drop", handleEvent);
//使用XHR上传文件-- 利用FormData对象
var droptarget = document.getElementById("droptarget");
function handleEvent(event){
var info = "",
output = document.getElementById("output"),
data, xhr,
files, i, len;
EventUtil.preventDefault(event);
if (event.type == "drop"){
data = https://www.it610.com/article/new FormData();
files = event.dataTransfer.files;
i = 0;
len = files.length;
while (i < len){
data.append("file" + i, files[i]);
i++;
}
xhr = new XMLHttpRequest();
xhr.open("post", "FileAPIExample06Upload.php", true);
xhr.onreadystatechange = function(){
if (xhr.readyState == 4){
alert(xhr.responseText);
}
};
xhr.send(data);
}
}
EventUtil.addHandler(droptarget, "dragenter", handleEvent);
EventUtil.addHandler(droptarget, "dragover", handleEvent);
EventUtil.addHandler(droptarget, "drop", handleEvent);
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- 【译】Rails|【译】Rails 5.0正式发布(Action Cable,API模式等)
- ElasticSearch6.6.0强大的JAVA|ElasticSearch6.6.0强大的JAVA API详解
- 前端开发|Vue2.x API 学习
- 简易有效Api接口防攻击策略
- 如何在Kubernetes|如何在Kubernetes 里添加自定义的 API 对象(一)
- fastapi教程翻译(一)(了解FastAPI结构)
- BLAS|BLAS API 中文文档(2)(待续)
- 1.前端引入jeDate日期控件
- 基础3-API-值传递