var manageCookies = {
set: function (key, value, expTime) {
document.cookie = key + '=' + value + ';max-age' + expTime;
return this;
},
delete: function (key) {
this.set(key, '', -1);
},
get: function (key, cb) {
var CookiesArray = document.cookie.split('; ');
for (var i = 0; i < CookiesArray.length; i++) {
var CookieItem = CookiesArray[i];
var CookieItemArray = CookieItem.split('=');
if (CookiesArray[0] === key) {
cb(CookiesArray[i]);
return this;
}
}
cn(undefined);
return this;
},
};
history.replaceState('this is test', null , 'test')
参数一 状态对象 参数二 替换的名字 参数三 改变的url地址
history.length 不会变

参数一 状态对象 参数二 替换的名字 参数三 改变的url地址
history.length 会变

在每一次活动的历史条目发生改变的时候 就会有一个popstate事件派发给window对象
所以如果想后退时显示相应的样 式 就可以监听popstate事件 获取相应的样式信息挂载
worker是异步的
worker是打印不出document window parent的
但是是可以发送AJAX请求
html文件
if (window.Worker) {
//实例化一个worker
var myWorker = new Worker('worker.js');
//声明信息
var message = { addThis: { num1: 1, num2: 1 } };
//传递信息
myWorker.postMessage(message);
//接收信息
myWorker.onmessage = function (e) {
console.log(e.data.result);
};
}
worker.js文件
this.onmessage = function (e) {
if (e.data.addThis !== undefined) {
var sumMessage = {
result: e.data.addThis.num1 + e.data.addThis.num2,
};
this.postMessage(sumMessage);
}
};

myWorker.terminate(); 终止worker 不再进行通信
再worker中使用importScripts(‘…’) 可以加载其他的worker
一个worker也可以委派任务给其他的worker
px 相对于屏幕像素
em 父级元素设置什么font-size = 1em
rem 根元素的HTML设置什么font-size = 1rem
document.addEventListener(
'touchstart',
function () {
console.log('touchstart');
},
false
);
document.addEventListener(
'touchmove',
function () {
console.log('touchmove');
},
false
);
document.addEventListener(
'touchend',
function () {
console.log('touchend');
},
false
);
document.addEventListener(
'touchcancel',
function () {
console.log('touchcancel');
},
false
);
setTimeout(() => {
alert('blocked');
}, 3000);


e.type返回事件名称
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Documenttitle>
<style>
div {
width: 100px;
height: 100px;
background-color: orange;
}
style>
head>
<body>
<div id="box">div>
<script>
document.addEventListener(
'touchstart',
function (e) {
console.log(e.type);
},
false
);
script>
body>
html>

e.touches所有触点
document.addEventListener(
'touchstart',
function (e) {
console.log(e.touches);
},
false
);

e.targetTouches 作用在当前元素的触点
document.addEventListener(
'touchstart',
function (e) {
console.log(e.targetTouches);
},
false
);

e.changedTouches 与当前事件相关的所有触点
document.addEventListener(
'touchstart',
function (e) {
console.log(e.changedTouches);
},
false
);

document.addEventListener(
'touchstart',
function (e) {
console.log(e.changedTouches[0]);
},
false
);
identifier触点的唯一标识

<body>
<div id="box">div>
<script>
(function (doc) {
var Touch = function (selector) {
return Touch.prototype.init(selector);
};
Touch.prototype = {
init: function (selector) {
if (typeof selector === 'string') {
this.elem = doc.querySelector(selector);
return this;
}
},
tap: function (callback) {
this.elem.addEventListener('touchstart', fn);
this.elem.addEventListener('touchend', fn);
var sTime, eTime;
function fn(e) {
e.preventDefault();
switch (e.type) {
case 'touchstart':
sTime = new Date().getTime();
case 'touchend':
eTime = new Date().getTime();
if (eTime - sTime < 500) {
callback.call(this, e);
}
break;
}
}
},
longtap: function (callback) {
this.elem.addEventListener('touchstart', fn, false);
this.elem.addEventListener('touchmove', fn, false);
this.elem.addEventListener('touchend', fn, false);
var t = null,
_self = this;
function fn(e) {
switch (e.type) {
case 'touchstart':
t = setTimeout(function () {
callback.call(_self, e);
}, 500);
case 'touchmove':
clearTimeout(t);
t = null;
break;
case 'touchend':
clearTimeout(t);
t = null;
break;
}
}
},
};
window.$ = window.Touch = Touch;
})(document);
$('#box').tap(function (e) {
console.log(1);
});
$('#box').longtap(function (e) {
console.log(1);
});
script>
body>