const heart_box = document.getElementById('heart')
// 创建标签
let element = document.createElement('div')
element.id = `heart_${keyName}`
element.style.cssText = styles.container
heart_box.appendChild(element)
// 移除标签
setTimeout(function(){
const heart_element = document.getElementById(`heart_${keyName}`)
heart_box.removeChild(heart_element)
const heart_style = document.getElementById(`heart_id_${keyName}`)
document.head.removeChild(heart_style)
}, 3000)
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);
}
});
}
readAsArrayBuffer(blob)
– 以二进制格式读取数据ArrayBuffer。readAsText(blob, [encoding])
– 以给定编码的文本字符串形式读取数据(utf-8默认情况下)。readAsDataURL(blob)
– 读取二进制数据并将其编码为 base64 数据 url。abort()
– 取消操作。<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>
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;'
);
let number = 4579
let hexStr = number.toString(16)
console.log(hexStr) // 11e3
let hexStr2 = '11e3'
let number2 = parseInt(hexStr2, 16)
console.log(number2) // 4579
let str = "Hello People"
let encodedString = btoa(str)
console.log(encodedString) // "SGVsbG8gUGVvcGxl"
let dec = atob(encodedString)
console.log(dec) // "Hello People"
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');
<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>