This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/ | |
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating | |
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel | |
// MIT license | |
(function() { | |
var lastTime = 0; | |
var vendors = ['ms', 'moz', 'webkit', 'o']; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(w){ | |
var perfNow; | |
var perfNowNames = ['now', 'webkitNow', 'msNow', 'mozNow']; | |
if(!!w['performance']) for(var i = 0; i < perfNowNames.length; ++i) | |
{ | |
var n = perfNowNames[i]; | |
if(!!w['performance'][n]) | |
{ | |
perfNow = function(){return w['performance'][n]()}; | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// relies on Date.now() which has been supported everywhere modern for years. | |
// as Safari 6 doesn't have support for NavigationTiming, we use a Date.now() timestamp for relative values | |
// if you want values similar to what you'd get with real perf.now, place this towards the head of the page | |
// but in reality, you're just getting the delta between now() calls, so it's not terribly important where it's placed | |
(function(){ | |
// prepare base perf object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<canvas id="cnv" width="100" height="100"></canvas> | |
<script> | |
var ctx = document.getElementById('cnv').getContext('2d'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts an image to | |
* a base64 string. | |
* | |
* If you want to use the | |
* outputFormat or quality param | |
* I strongly recommend you read the docs | |
* @ mozilla for `canvas.toDataURL()` | |
* | |
* @param {String} url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Check transparent canvas</title> | |
</head> | |
<body> | |
<canvas id='editor' style='border:solid'></canvas> | |
<canvas id='blank' style='display:none'></canvas> | |
<script> | |
canvas = document.getElementById('editor'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function touchHandler(event) | |
{ | |
var touches = event.changedTouches, | |
first = touches[0], | |
type = ""; | |
switch(event.type) | |
{ | |
case "touchstart": type = "mousedown"; break; | |
case "touchmove": type="mousemove"; break; | |
case "touchend": type="mouseup"; break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countProperties(obj) { | |
var count = 0, | |
k; | |
for (k in obj) { | |
if (obj.hasOwnProperty(k)) { | |
count += 1; | |
} | |
} | |
return count; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shuffle(array) { | |
var counter = array.length, temp, index; | |
// While there are elements in the array | |
while (counter--) { | |
// Pick a random index | |
index = (Math.random() * (counter+1)) | 0; | |
// And swap the last element with it | |
temp = array[counter]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function removeChildren(elem) { | |
var last; | |
while (last = elem.lastChild) { | |
elem.removeChild(last); | |
} | |
} |
OlderNewer