58
  function animate(options) {
    var start = performance.now();
    requestAnimationFrame(function animate(time) {
      // timeFraction от 0 до 1
      var timeFraction = (time - start) / options.duration;
      if (timeFraction > 1) timeFraction = 1;

      // текущее состояние анимации
      var progress = options.timing(timeFraction)
      
      options.draw(progress);

      if (timeFraction < 1) {
        requestAnimationFrame(animate);
      }
    });
  }
Camila Waz 2022-03-07 13:41:42
95
  • readAsArrayBuffer(blob)– 以二进制格式读取数据ArrayBuffer。
  • readAsText(blob, [encoding])– 以给定编码的文本字符串形式读取数据(utf-8默认情况下)。
  • readAsDataURL(blob)– 读取二进制数据并将其编码为 base64 数据 url。
  • abort()– 取消操作。
  • 更多方法:https://javascript.info/file
Camila Waz 2022-03-07 10:46:42
282访问人次
Camila Waz 2022-03-15 15:13:54
33
<form id="formElem">
  <input type="text" name="name" value="John">
  <input type="text" name="surname" value="Smith">
  <input type="submit">
</form>

<script>
  formElem.onsubmit = async (e) => {
    e.preventDefault();

    let response = await fetch('/article/formdata/post/user', {
      method: 'POST',
      body: new FormData(formElem)
    });

    let result = await response.json();

    alert(result.message);
  };
</script>
Camila Waz 2022-03-07 09:56:00
35

good博客 图片

Camila Waz 2022-03-07 09:31:16
10
let arr1 = [1, 2, 3, 4, 5];
let arr2 = [5, 6, 7, 8];
let difference = arr1.filter(x => !arr2.includes(x));
console.log(difference);  // [1, 2, 3, 4]
Camila Waz 2022-03-04 15:03:58
16

Math.max() 方法

let arrayOfNumbers = [4, 12, 62, 70, -10];
console.log(Math.max(...arrayOfNumbers)); // returns 70

apply() 方法

Math.min.apply(Math, testArr);
Math.max.apply(Math, testArr);

let arrayOfNumbers = [4, 12, 62, 70, -10];
console.log(Math.max.apply(Math, arrayOfNumbers)); // returns 70
Camila Waz 2022-03-04 14:54:52
7

match()

let temp = "Welcome to good1230.com";
let count = (temp.match(/to/g) || []).length;
console.log(count);

split()

let theString = "Welcome to good1230.com";
console.log(theString.split("o").length - 1);
Camila Waz 2022-03-04 14:45:04
37
function toDataURL(url, callback) {
  let xhRequest = new XMLHttpRequest();
  xhRequest.onload = function () {
    let reader = new FileReader();
    reader.onloadend = function () {
      callback(reader.result);
    }
    reader.readAsDataURL(xhRequest.response);
  };
  xhRequest.open('GET', url);
  xhRequest.responseType = 'blob';
  xhRequest.send();
}
toDataURL('static/emoji_01.png', function (dataUrl) {
  console.log('RESULT:', dataUrl)
})
Camila Waz 2022-03-04 14:34:19
11
function rgbToHex(r, g, b) {
  return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
}
console.log(rgbToHex(28, 135, 201)); // #1c87c9
Camila Waz 2022-03-04 14:15:42
15
console.log('%c Hi everyone!', 'color: #1c87c9; font-size: 18px');
console.log('%c Style 1! %c Style 2!',
  'color: #1c87c9; background: #ccc; font-size: 20px;', 
  'color: #8ebf42; background: # 666; font - size: 20 px;'
);
Camila Waz 2022-03-04 14:05:34