Skip to content

Instantly share code, notes, and snippets.

@PAEz
PAEz / what-forces-layout.md
Created July 4, 2023 04:15 — 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
@PAEz
PAEz / dom-helper.js
Created March 31, 2017 07:36 — forked from SitePointEditors/dom-helper.js
Mini jQuery, sort of.
/**
* A collection of helper prototype for everyday DOM traversal, manipulation,
* and event binding. Sort of a minimalist jQuery, mainly for demonstration
* purposes. MIT @ m3g4p0p
*/
window.$ = (function (undefined) {
/**
* Duration constants
* @type {Object}
@PAEz
PAEz / promise_while_loop.js
Last active February 5, 2017 06:33 — forked from victorquinn/promise_while_loop.js
Promise "loop" using the Bluebird library Updated to p1nox's comment from the original
/*
p1nox commented 19 days ago
I was digging a bit about this and I found some interesting links:
petkaantonov/bluebird#553 (comment)
http://stackoverflow.com/a/29396005
http://stackoverflow.com/a/24660323
Simplifications:
*/
var p1 = {
x: 20,
y: 20
};
var p2 = {
x: 40,
y: 40
};
function getFnName(fn) {
var f = typeof fn == 'function';
var s = f && ((fn.name && ['', fn.name]) || fn.toString().match(/function ([^\(]+)/));
return (!f && 'not a function') || (s && s[1] || 'anonymous');
}
console.log(getFnName(String)); // 'String'
console.log(getFnName(function test(){})); // 'test'
console.log(getFnName(function (){})); // 'anonymous'
(function(window){
var EVENT_EXISTS = 'GlobalEvents: Event already exists.';
var eventIsRunning,
_eventStack,
_findByName,
stackEvent,
removeEvent,
eventListener,