Skip to content

Instantly share code, notes, and snippets.

@paulirish
paulirish / what-forces-layout.md
Last active June 19, 2025 14:36
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
@b4tman
b4tman / fan_ctrl.py
Last active January 8, 2025 15:16
Включение и регулировка скорости вращения вентилятора в зависимости от температуры для Raspberry Pi с помощью программной реализации ШИМ
#!/usr/bin/env python
# coding: utf8
# скрипт мониторит температуру, и с помощью ШИМ управляет
# GPIO пином (0-3В), который должен быть подключен на базу транзистора,
# который является ключем в цепи питания вентилятора (5В).
# пример подключения вентилятора через ключ:
# https://easyeda.com/b4tman.p2p/rpi-fan-01
# параметры:
@nickdavis
nickdavis / acf-fields-repeater.php
Created November 10, 2016 10:59
Advanced Custom Fields > Repeater field example (set programatically)
<?php
add_action( 'acf/init', 'nd_acf_add_local_field_groups' );
/**
* Add Advanced Custom Fields programatically (Repeater field).
*
* @link https://www.advancedcustomfields.com/resources/register-fields-via-php/
* @link https://support.advancedcustomfields.com/forums/topic/register-two-locations-via-php-doesnt-work/
* @link https://support.advancedcustomfields.com/forums/topic/adding-additional-layout-to-flexible_content-field-in-child-theme/
*
var l=['keydown','keypress','keyup','fullscreenerror','resize','scroll','submit','copy','paste','mouseover','mousemove','mousedown','mouseup','auxclick','click','dblclick','contextmenu','wheel','mouseleave','mouseout','select','pointerlockchange','pointerlockerror','drag','dragend','dragenter','dragover','dragleave','drop'],a=false;
dfwp_unregister = function(){
l.map(function(el){window.removeEventListener(el,dfwp_initGtm)});
};
dfwp_initGtm = function(){
if (!a){
a=true;
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
@ChrisFlannagan
ChrisFlannagan / geodistance.php
Created October 13, 2017 16:52
Calculate distance between to coordinates of latitude and longitude using the WP REST API and return posts ordered by distance from user's coordinates
<?php
/**
* Heavily borrowed from: http://xplus3.net/2010/08/08/filtering-on-a-non-standard-database-field-with-wordpress/
**/
class CoordinatesTable extends DB {
protected $db_option = "coordinates_db";
@prasetyop
prasetyop / admin.css
Last active March 13, 2023 13:33
Flexible Content Preview Pop Up
.acf-fc-popup .preview {
position: absolute;
right: 100%;
margin-right: 0px;
top: 0;
background: #383c44;
min-height: 100%;
border-radius: 5px;
align-content: center;
display: grid;
{
"vars": {
"account": "account_name",
"profile": "profile_name",
"visitor_id": "CLIENT_ID(AMP_ECID_GOOGLE)",
"gclid": "${queryParam(gclid)}"
},
"extraUrlParams": {
"page_name": "home page for company x",
@mbaersch
mbaersch / callback-example.js
Last active July 16, 2020 14:16
Upgrade Your Analytics Cookies to fight ITP2.1:
/* GTM : use the following code inside a customTask, hitCallback oder a cleanup tag
GA.JS : modify your existing tracking code with a customTask or hitCallback and execute the following code
GTAG.JS : modify your existing tracking code with a manual page_view event
including an event_callback (gtag.js) and execute the following code
customTask ga.js - see: https://developers.google.com/analytics/devguides/collection/analyticsjs/tasks#adding_to_a_task
hitCallback ga.js - see: https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#hitcallback
event_callback gtag.js - see: https://developers.google.com/analytics/devguides/collection/gtagjs/sending-data#implement_event_callback_functions
*/