Skip to content

Instantly share code, notes, and snippets.

View liuyib's full-sized avatar

云泥 liuyib

View GitHub Profile
@liuyib
liuyib / what-forces-layout.md
Created July 29, 2022 02:22 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@liuyib
liuyib / useRect.js
Created June 7, 2021 16:13 — forked from morajabi/useRect.js
useRect — getBoundingClientRect() React Hook with resize handler
import { useLayoutEffect, useCallback, useState } from 'react'
export const useRect = (ref) => {
const [rect, setRect] = useState(getRect(ref ? ref.current : null))
const handleResize = useCallback(() => {
if (!ref.current) {
return
}
@liuyib
liuyib / format-detection.html
Created July 15, 2020 07:46 — forked from yuezk/format-detection.html
HTML format-detection meta tag
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="date=no">
<meta name="format-detection" content="address=no">
<meta name="format-detection" content="email=no">
@liuyib
liuyib / ajax-es5.js
Last active April 14, 2020 08:06
ajax es5 / es6 version(dev)
var ajax = function (options) {
var method = options.method;
var url = options.url;
var body = options.body;
var headers = options.headers;
var fnSucc = options.fnSucc;
var fnFail = options.fnFail;
var xhr = new XMLHttpRequest();
@liuyib
liuyib / cookie.js
Last active May 5, 2020 15:45
set / get / delete cookie
@liuyib
liuyib / my_utils.js
Last active April 13, 2020 15:58
常用 utils 函数
/**
* 判断是否是字符串
*
* @param {*} val 待判断的值
* @returns {boolean} 是:true,不是:false
*/
function isString(val) {
return typeof val === 'string';
}
@liuyib
liuyib / minimum-image.txt
Last active March 25, 2021 09:31
Minimum image (base64)
<!-- 1 * 1 像素的透明 gif 图片 -->
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">
<!-- 1 * 1 像素(#000000) -->
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs=">
<!-- 1 * 1 像素(#f2f2f2) -->
data:image/gif;base64,R0lGODlhAQABAPAAAPLy8gAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==
@liuyib
liuyib / .cz-config.js
Created May 22, 2019 05:32 — forked from leohxj/.cz-config.js
cz-customizable with emoji
'use strict';
module.exports = {
types: [
{
value: 'WIP',
name : '💪 WIP: Work in progress'
},
{