ybg555 / noteBook

踩坑指南
0 stars 0 forks source link

Snippet #3

Open ybg555 opened 8 years ago

ybg555 commented 8 years ago

//判断浏览器缩放比 function detectZoom() { var ratio = 0, screen = window.screen, ua = navigator.userAgent.toLowerCase();

    if (window.devicePixelRatio !== undefined) {
        ratio = window.devicePixelRatio;
    } else if (~ua.indexOf('msie')) {
        if (screen.deviceXDPI && screen.logicalXDPI) {
            ratio = screen.deviceXDPI / screen.logicalXDPI;
        }
    } else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
        ratio = window.outerWidth / window.innerWidth;
    }
    if (ratio) {
        ratio = Math.round(ratio * 100);
    }
    console.log(ratio);
}
ybg555 commented 7 years ago

afefe

ybg555 commented 6 years ago
// 2 3 5 4 1
setTimeout(function() {
  console.log(1)
}, 0);
new Promise(function executor(resolve) {
  console.log(2);
  for( var i=0 ; i<10000 ; i++ ) {
    i == 9999 && resolve();
  }
  console.log(3);
}).then(function() {
  console.log(4);
});
console.log(5);
ybg555 commented 5 years ago

vue timer

timer() { if (this.time > 0) { this.time--; setTimeout(this.timer, 1000); } },

ybg555 commented 5 years ago

手机号模糊 4 位

phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');