82
  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);
      }
    });
  }
H5页面 Camila Waz 2022-03-07 13:41:42
137
  • readAsArrayBuffer(blob)– 以二进制格式读取数据ArrayBuffer。
  • readAsText(blob, [encoding])– 以给定编码的文本字符串形式读取数据(utf-8默认情况下)。
  • readAsDataURL(blob)– 读取二进制数据并将其编码为 base64 数据 url。
  • abort()– 取消操作。
  • 更多方法:https://javascript.info/file
H5页面 Camila Waz 2022-03-07 10:46:42
593访问人次
Camila Waz 2022-09-02 19:01:05
43
<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>
H5页面 Camila Waz 2022-03-07 09:56:00
22
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;'
);
H5页面 Camila Waz 2022-03-04 14:05:34
3
let number = 4579
let hexStr = number.toString(16)
console.log(hexStr)  // 11e3

let hexStr2 = '11e3'
let number2 = parseInt(hexStr2, 16)
console.log(number2)  // 4579
H5页面 Camila Waz 2022-03-04 13:46:49
9
let str = "Hello People"
let encodedString = btoa(str)
console.log(encodedString) // "SGVsbG8gUGVvcGxl"

let dec = atob(encodedString)
console.log(dec) // "Hello People"
H5页面 Camila Waz 2022-03-04 13:37:21
15
canvas.toBlob(function(blob) {
  // blob ready, download it
  let link = document.createElement('a');
  link.download = 'example';

  link.href = URL.createObjectURL(blob);
  link.click();

  // delete the internal blob reference, to let the browser clear memory from it
  URL.revokeObjectURL(link.href);
}, 'image/jpg');
H5页面 Camila Waz 2022-03-04 11:09:33
28
<a download="hello.txt" href='#' id="link">Download</a>

<script>
   let blob = new Blob(["Hello, world!"], {type: 'text/plain'}); 
   link.href = URL.createObjectURL(blob);
</script>
H5页面 Camila Waz 2022-03-04 10:29:11