css篇(scss)
清除默认样式
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header,
menu, nav, output, ruby, section, summary,
time, mark, audio, video, input {
margin: 0;
padding: 0;
border: 0;
vertical-align: baseline;
box-sizing: border-box;
}
article, aside, details, figcaption, figure,
footer, header, menu, nav, section {
display: block;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
a {
-webkit-backface-visibility: hidden;
text-decoration: none;
outline: none;
-webkit-tap-highlight-color: rgba(255, 0, 0, 0);
}
a:hover {
text-decoration: none;
}
li {
list-style: none;
}
body {
-webkit-text-size-adjust: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
a, button, input { //清除点击效果
-webkit-tap-highlight-color: #fff;
}
input { //清除聚焦时边框
outline: none;
}
img {
-webkit-touch-callout: none;
width: 100%;
height: 100%;
}
复用scss
@mixin text-overflow($line:1) {
@if $line==1 {
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
@else {
display: -webkit-box;
-webkit-line-clamp: $line;
-webkit-box-orient: vertical;
overflow: hidden;
text-overflow: ellipsis;
}
}
@mixin flex-center {
display: flex;
justify-content: center;
align-items: center;
}
@mixin flex($justify:flex-start, $align:flex-start) {
display: flex;
justify-content: $justify;
align-items: $align;
}
@mixin absolute-center {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
@mixin absolute-bottom {
position: absolute;
bottom: 0;
left: 0;
}
@mixin mask($color: $color-black-85, $index: 101) {
position: fixed;
left: 0;
right: 0;
top: 0;
bottom: 0;
background: $color;
z-index: $index;
}
@mixin bgImage($url, $position: center, $size: 100%) {
background-image: url($url);
background-repeat: no-repeat;
background-position: $position;
background-size: $size;
}
@mixin circle($size) {
width: $size;
height: $size;
border-radius: 50%;
overflow: hidden;
}
@mixin text-center($height) {
text-align: center;
height: $height;
line-height: $height;
}
@mixin close_btn {
position: absolute;
right: 30px;
top: 30px;
width: 40px;
height: 40px;
z-index: 101;
&::after {
content: '';
position: absolute;
left: 0;
top: 10px;
width: 40px;
height: 5px;
border-radius: 10px;
background: #999;
transform: rotate(45deg);
-ms-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-webkit-transform: rotate(45deg);
-o-transform: rotate(45deg);
z-index: 99;
transform-origin: center center;
}
&::before {
content: '';
position: absolute;
left: 0;
top: 10px;
width: 40px;
height: 5px;
border-radius: 10px;
background: #999;
transform: rotate(135deg);
-ms-transform: rotate(135deg);
-moz-transform: rotate(135deg);
-webkit-transform: rotate(135deg);
-o-transform: rotate(135deg);
z-index: 99;
transform-origin: center center;
}
}
js篇
关于缓存
let Storage = {
sessionSet(name, data) {
sessionStorage.removeItem(name);
sessionStorage.setItem(name, JSON.stringify(data));
},
sessionGet(name) {
return JSON.parse(sessionStorage.getItem(name));
},
sessionRemove(name) {
sessionStorage.removeItem(name);
},
localSet(name, data) {
localStorage.removeItem(name);
localStorage.setItem(name, JSON.stringify(data));
},
localGet(name) {
return JSON.parse(localStorage.getItem(name));
},
localRemove(name) {
localStorage.removeItem(name);
}
};
export default Storage;
节流函数
let util = {
/*节流函数,通过控制每次事件执行的时间间隔控制短时间多次执行方法
fn: 要执行的方法
wait:每次事件执行的推迟时间(毫秒)
immediate: 是否立即执行
*/
throttle: (fn, wait, immediate) =>
util.debounceOrThrottle(fn, wait, immediate, true),
debounceOrThrottle(
fn,
wait = 300,
immediate = false,
executeOncePerWait = false
) {
if (typeof fn !== "function") {
console.error("传入参数必须为函数")
return
}
let tId = null
let context = null
let args = null
let lastTriggerTime = null
let result = null
let lastExecutedTime = null
const later = function() {
const last =
Date.now() - (executeOncePerWait ? lastExecutedTime : lastTriggerTime)
if (last < wait && last > 0) {
setTimeout(later, wait - last)
} else {
if (!immediate) {
executeOncePerWait && (lastExecutedTime = Date.now())
result = fn.apply(context, args)
context = args = null
}
tId = null
}
}
return function() {
context = this
args = arguments
!executeOncePerWait && (lastTriggerTime = Date.now())
const callNow = immediate && !tId
if (!tId) {
executeOncePerWait && (lastExecutedTime = Date.now())
tId = setTimeout(later, wait)
}
if (callNow) {
executeOncePerWait && (lastExecutedTime = Date.now())
result = fn.apply(context, args)
context = args = null
}
return result
}
},
// 复制内容
onCopy(content) {
let oInput = document.createElement("input")
oInput.value = content
document.body.appendChild(oInput)
oInput.select()
console.log(oInput.value)
document.execCommand("Copy")
oInput.remove()
}
}
module.exports = util