1 设置document.title(兼容微信浏览器)
1 setDocumentTitle(t){ 2 document.title = t; 3 let i = document.createElement('iframe'); 4 i.src = 'https://app.img.kangfuzi.com/icon/favicon.ico'; 5 i.style.display = 'none'; 6 i.onload = function () { 7 setTimeout(function () { 8 i.parentNode.removeChild(i); 9 }, 9); 10 }; 11 document.body.appendChild(i); 12 }
2 获取css属性(兼容IE)
1 getCss(curEle,attr){ 2 let val = null; 3 let reg = null; 4 if("getComputedStyle" in window){ 5 val = window.getComputedStyle(curEle,null)[attr]; 6 } else { //ie6~8不支持上面属性 7 if(attr === "opacity"){ 8 val = curEle.currentStyle["filter"]; 9 reg = /^alpha(opacity=(d+(?:.d+)?))$/i; 10 val = reg.test(val)?reg.exec(val)[1]/100:1; 11 } else { 12 val = curEle.currentStyle[attr]; 13 } 14 } 15 reg = /^(-?d+(.d)?)(px|pt|em|rem)?$/i; 16 return reg.test(val)?parseFloat(val):val; 17 }
3 深Copy
function extend( dest, ...sources ) { const obj = sources[ 0 ]; for( let property in obj ) { if( obj.hasOwnProperty( property ) ) { dest[ property ] = obj[ property ]; } } if( sources.length > 1 ) { return extend( dest, ...sources.splice( 1, sources.length - 1 ) ); } return dest; }