Skip to content

Instantly share code, notes, and snippets.

@paulirish
paulirish / what-forces-layout.md
Last active April 26, 2024 17:33
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
@ratherironic
ratherironic / idonteven.css
Last active December 27, 2015 12:48
This is kinda amazing that this Works : JS in CSS
#emptyDiv:after {
content: 'alert("you gotta be kidding me")';
}
@johnpolacek
johnpolacek / responsive-viewport
Created November 16, 2012 18:57
Responsive Viewport
<script language="javascript">
// set viewport to zoom to 1200px wide on viewports > 640px wide
var viewPortTag = document.createElement('meta');
viewPortTag.id = 'viewport';
viewPortTag.name = 'viewport';
if (screen.width > 640) {
viewPortTag.content = 'width=1200';
} else {
viewPortTag.content = 'width=device-width';
}
@bejes
bejes / spancount.js
Created October 19, 2012 02:29
Simple jquery plugin to insert spans in text and a defined character limit
/**
* Plugin function to insert spans into text:
* usage
* $(document).ready(function() {
* $('p.charcount').charSpanCount(); });
* or $(document).ready(function() {
* $('p.charcount').charSpanCount({'charcount' : 15});
* });
*/
(function($) {
@cvuletich
cvuletich / gist:2829385
Created May 29, 2012 16:27
CSS3 Ring Pulsers
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Ring Pulsers</title>
<style type="text/css" media="screen">
.marker {
left: 150px;
height: 100px;
position: absolute;
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@alex-gist
alex-gist / dateExtend.js
Created March 12, 2012 16:47 — forked from rwbaker/dateExtend.js
JavaScript: Extend JavaScript Date
//Extend Date to have a few extra fatures
Date.dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
Date.monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
Date.prototype.dayNames = Date.dayNames;
Date.prototype.monthNames = Date.monthNames;
Date.prototype.getDayName = function() {
return this.dayNames[this.getDay()];
};
Date.prototype.getDayNameAbbr = function() {
@nathansmith
nathansmith / 1_form-reset.scss
Last active September 8, 2019 09:33
Form Reset
// `Default font for form elements.
//----------------------------------------------------------------------------------------------------
$form-font-stack: Arial, "Liberation Sans", FreeSans, sans-serif !default;
$form-font-size: 13px !default;
// `Form Element Reset.
//----------------------------------------------------------------------------------------------------
input::ms-clear,
@addyosmani
addyosmani / pubsub.md
Created October 28, 2011 06:49
Four ways to do Pub/Sub with jQuery 1.7 and jQuery UI (in the future)

#Four Ways To Do Pub/Sub With jQuery and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],