This presentation is an HTML5 website
Press → key to advance.
Zoom in/out: Ctrl or Command + +/-
var i,
items = ['a','b','c','d','e'];
for ( i = 0; i < items.length; i++ ) {
// Do stuff
}
var i, li,
items = ['a','b','c','d','e'];
for ( i = 0, il = items.length; i < il; i++ ) {
// Do stuff faster
}
(function ( lib ) {
"use strict";
// Your code...
}( window.lib ));

<html>
<head>
<title>Awesomeness!</title>
</head>
<body>
<p>
This is
awesome!
</p>
<img src="cool.png">
<div style="display: none;">
Hidden picaboo content
</div>
</body>
</html>
html
head
title
body
p
[text node]
img
div
[text node]
root
body
p
text line 1
text line 2
img
Happens when something changes without altering the page layout.
Ex: Changing the background color of a element causes a repaint.
Happens when something changes so it does alter the page layout.
Ex: Changes to a elements width / height can cause a reflow.
clientHeight, clientLeft, clientTop, clientWidth, focus(), getBoundingClientRect(), getClientRects(), innerText, offsetHeight, offsetLeft, offsetParent, offsetTop, offsetWidth, outerText, scrollByLines(), scrollByPages(), scrollHeight, scrollIntoView(), scrollIntoViewIfNeeded(), scrollLeft, scrollTop, scrollWidth
height, width
getBoundingClientRect(), getClientRects()
computeCTM(), getBBox()
getCharNumAtPosition(), getComputedTextLength(), getEndPositionOfChar(), getExtentOfChar(), getNumberOfChars(), getRotationOfChar(), getStartPositionOfChar(), getSubStringLength(), selectSubString()
instanceRoot
getComputedStyle(), scrollBy(), scrollTo(), scrollX, scrollY, webkitConvertPointFromNodeToPage(), webkitConvertPointFromPageToNode()
Totally avoiding redraws and reflows are almost impossible. Keep them to a minimum!
<img src="foo.png">
<img src="foo.png" width="400" height="400">
.fooLayer {
position: absolute;
top: 400px;
left: 200px;
width: 200px;
height: 200px;
}
var e1 = $('#e1').css('left');
$('#e3').css('left', e1).css('width', 100).css('height', 100);
var e2 = $('#e2').css('left');
$('#e4').css('left', e2).css('width', 100).css('height', 100);
var e1 = $('#e1').css('left');
var e2 = $('#e2').css('left');
$('#e3').css('left', e1).css('width', 100).css('height', 100);
$('#e4').css('left', e2).css('width', 100).css('height', 100);
var i = 100, li, txt,
ul = document.getElementById( 'ulElement' );
while ( i-- ) {
li = document.createElement( 'li' );
txt = document.createTextNode( i );
li.appendChild( txt );
ul.appendChild( li );
}
var i = 100, li, txt,
ul = document.createDocumentFragment( 'ul' );
while ( i-- ) {
li = document.createElement( 'li' );
txt = document.createTextNode( i );
li.appendChild( txt );
ul.appendChild( li );
}
document.body.appendChild( ul );
var i = 100, li, txt,
ul = document.getElementById( 'ulElement' ),
clone = ul.cloneNode( true );
while ( i-- ) {
li = document.createElement( 'li' );
txt = document.createTextNode( i );
li.appendChild( txt );
clone.appendChild( li );
}
ul.parentNode.replaceChild( clone, ul );
var i = 100, li, txt,
ul = document.getElementById( 'ulElement' );
ul.style.display = 'none';
while ( i-- ) {
li = document.createElement( 'li' );
txt = document.createTextNode( i );
li.appendChild( txt );
ul.appendChild( li );
}
ul.style.display = 'block';
document.getElementById('foo').title = 'Foo element';
document.getElementById('foo').style.height = '200px';
document.getElementById('foo').style.width = '200px';
document.getElementById('foo').style.backgroundColor = 'orange';
var fooEl = getElementById('foo');
fooEl.title = 'Foo element';
fooEl.style.height = '200px';
fooEl.style.width = '200px';
fooEl.style.backgroundColor = 'orange';
var fooEl = getElementById('foo');
fooEl.style.fontSize = ( fooEl.offsetWidth / 10 ) + 'px';
fooEl.firstChild.style.marginLeft = ( fooEl.offsetWidth / 20 ) + 'px';
fooEl.style.left = ( ( -1 * fooEl.offsetWidth ) / 2 ) + 'px';
var fooEl = getElementById('foo');
var width = fooEl.offsetWidth;
fooEl.style.fontSize = ( width / 10 ) + 'px';
fooEl.firstChild.style.marginLeft = ( width / 20 ) + 'px';
fooEl.style.left = ( ( -1 * width ) / 2 ) + 'px';
var fooEl = getElementById('foo');
fooEl.style.backgroundColor = '#333';
fooEl.style.color = '#999';
fooEl.style.border = '1px solid #999';
var fooEl = getElementById('foo');
fooEl.setAttribute('style', 'background-color: #333; color: #999; ... ');
.fooStyle {
background-color: #333;
color: #999;
border: 1px solid #999;
}
var fooEl = getElementById('foo');
fooEl.className = 'fooStyle';
var pEls = document.getElementsByTagName('p'),
txt;
for ( var i = 0; i < pEls.length; i++ ) {
txt = document.createTextNode( i );
pEls[ i ].appendChild( txt );
}
var pEls = document.getElementsByTagName('p'),
txt,
cache = [];
for ( var i = 0; i < pEls.length; i++ ) {
cache[ cache.length ] = pEls[ i ];
}
for( i = 0; i < cache.length; i++ ) {
txt = document.createTextNode( i );
cache[ i ].appendChild( txt );
}
$("#fooEl").animate({ left: 300 }, 200 )
.animateLinear {
left: 300px;
-webkit-transition: all 200ms linear;
-moz-transition: all 200ms linear;
-o-transition: all 200ms linear;
transition: all 200ms linear;
}
.animateLinear {
left: 300px;
-webkit-transition: all 200ms linear;
-moz-transition: all 200ms linear;
-o-transition: all 200ms linear;
transition: all 200ms linear;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
<html>
<head>
<title>Awesomeness!</title>
</head>
<body>
<div>
<div>
<-- Some content -->
</div>
<div>
<div id="foo">
Click foo!
</div>
<div id="bar">
Click bar!
</div>
</div>
</div>
</body>
</html>
var fooEl = document.getElementById('foo'),
barEl = document.getElementById('bar');
fooEl.addEventListener('click', function () {
// Do something foo'ish
})
barEl.addEventListener('click', function () {
// Do something bar'ish
})
window.addEventListener('click', function ( ev ) {
var id = ev.target.getAttribute('id');
if ( id === 'foo' ) {
// Do something foo'ish
} else if ( id === 'bar') {
// Do something bar'ish
}
})
The browser needs to evaluate them
div#foo { }
body * { }
.fooElement * { }
body > * { }
.fooBox > * { }
ul li a { }
#head h1 { }
* html #fooBox ul li a { }
ul > li > a { }
#header > h3 { }
@trygve_lie
http://www.trygve-lie.com/