圣杯布局
<div class="container">
<div class="main"></div>
<div class="left"></div>
<div class="right"></div>
</div>
.container{padding-left:200px; padding-right:200px}
.left,.right{position:relative; width:200px; height:100%}
.left{float:left; left:-200px; margin-left:-100%; }
.right{float:right; right:-200px; margin-left:-200px;}
双飞翼布局
<div class="container">
<div class="main">
<div class="inner">inner</div>
</div>
<div class="left"></div>
<div class="right"></div>
</div>
.container>div{float:left; height:100%}
.main{width:100%; float:left;}
.inner{margin-left:200px; margin-right:200px}
.left{margin-left:-200px; width:200px;}
.right{margin-left:-200px; width:200px}
浮动布局
<div class="container">
<div class="left"></div>
<div class="right"></div>
<div class="main"></div>
</div>
.container>div{height:100%}
.left{float:left; width:200px}
.right{float:right; width:200px}
.main{margin-left:200px; margin-right:200px}
数组去重
function unique(array) {
var res = array.filter(function(item, index, arr){
return arr.indexOf(item) === index;
})
return res;
}
获取url参数
function getParam(url){
url = url == null?window.location.url:url;
var search = url.substring(url.lastIndexOf("?")+1);
if(!search){return{}}
return JSON.parse(
'{"') + decodeURIComponent(search).replace(/"/g,'\\"').replace(/&/g,'","').replace(/=/g,'":"')+'"}'
}
深拷贝
function deepClone(target){
if(typeof target === 'object'){
let cloneTarget = Array.isArray(target)?[]:{};
for( const key in target) {
cloneTarget[key] = deepClone(target[key])
}
return cloneTarget
} else {
return target
}
}