梁小新blog

记录常忘代码

border-1px
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
&::after {
content: '';
position: absolute;
top: 0;
left: 0;
width: 200%;
height: 200%;
-webkit-transform: scale(.5);
transform: scale(.5);
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
pointer-events: none;
box-sizing: border-box;
border: 0 solid #ccc;
border-left-width: 1px;
}
单行省略
1
2
3
overflow: hidden;
text-overflow:ellipsis;
white-space: nowrap;
多行省略
1
2
3
4
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
字符串截取
1
2
3
slice(start,[end])
substring(start,[end])
substr(start,[length])
远程登录服务器命令
1
2
3
$ ssh root@host
bash ssr.sh
复制文字到粘贴板

可以使用 https://github.com/zenorocha/clipboard.js 兼容性较好

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 复制文字功能
export const copyContent = function(elementId) {
// 动态创建 input 元素
var aux = document.createElement("input");
// 获得需要复制的内容
aux.setAttribute("value", document.getElementById(elementId).innerHTML);
// 添加到 DOM 元素中
document.body.appendChild(aux);
// 执行选中
// 注意: 只有 input 和 textarea 可以执行 select() 方法.
aux.select();
// 获得选中的内容
var content = window.getSelection().toString();
// 执行复制命令
document.execCommand("copy");
// 将 input 元素移除
document.body.removeChild(aux);
}
深度克隆
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export const deepClone = function(obj) {
if (Array.isArray(obj)) {
return obj.map(deepClone)
} else if (obj && typeof obj === 'object') {
var cloned = {}
var keys = Object.keys(obj)
for (var i = 0, l = keys.length; i < l; i++) {
var key = keys[i]
cloned[key] = deepClone(obj[key])
}
return cloned
} else {
return obj
}
}