zoukankan      html  css  js  c++  java
  • 9 Utils

    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;
    }
  • 相关阅读:
    Debug和Release区别
    C语言程序_管理系统
    读书的学问
    御姐的含义
    进制的英文书写
    CHM文件无法打开的解决方法
    819代码
    点击链接不跳转或刷新
    MS SqlServer 随机查询并随机排序
    Html背景图
  • 原文地址:https://www.cnblogs.com/drop-in-ocean/p/7509883.html
Copyright © 2011-2022 走看看