This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createMaskElement() { | |
// 1. 做一個空的 <p> 充當我們的 offset | |
let offset = document.createElement("p") | |
// 這行其實可以省略 | |
offset.innerHTML = "" | |
// Browser Default 都會給 Element margin 16px , 這裡為了保持數據上的乾淨 , 直接歸零 | |
offset.style.margin = "0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function triggerMask() { | |
// 1. 找到遮罩 | |
let mask = document.getElementById("mask") | |
// 2. 當我滑到 多少高度時 | |
let flag = window.scrollY >= 50 | |
// 把遮罩打開 | |
mask.style.display = flag ? "none" : "block" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function throttleBy(func) { | |
let skip = false; | |
return async function call(...args) { | |
if (skip) return; | |
skip = true; | |
const result = await func(...args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {defineProperty} = Object; | |
function observe({key, value, onChange}, it) { | |
const descriptor = { | |
get() { | |
return value; | |
}, | |
set(newValue) { | |
value = newValue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Timer() { | |
const start = performance.now(); | |
return function get() { | |
return performance.now() - start; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Execute a function repeatedly when frame change. | |
* @param {Function} func | |
* @param {any} args | |
* @return {stop} : Function to stop the loop | |
*/ | |
function frameLoop(func, ...args) { | |
let loop = true; | |
(async function execute() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Simple JSX</title> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Loader } from 'pixi.js'; | |
import { Howl } from 'howler'; | |
const loader = new Loader(); | |
loader.pre(SoundHandler); | |
function SoundHandler(resource, next) { | |
const SUPPORT_FORMATS = ['mp3', 'opus', 'ogg', 'wav', 'aac', 'm4a', 'm4b', 'mp4', 'webm']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function KeyBoard(keymap) { | |
const pressing = new Set(); | |
window.addEventListener("keydown", ({ key }) => | |
keymap[key] && pressing.add(keymap[key]) | |
); | |
window.addEventListener("keyup", ({ key }) => | |
keymap[key] && pressing.delete(keymap[key]) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ReactNode, isValidElement, PropsWithChildren } from "react"; | |
type Props<T> = Pick<PropsWithChildren<T>, Exclude<keyof T, "children">>; | |
function isFunction<T, R>(instance: any): instance is (props: T) => R { | |
return typeof instance === "function"; | |
} | |
export default function RenderProps<T>({ | |
children, |
OlderNewer