Skip to content

Instantly share code, notes, and snippets.

@exonen
exonen / scrollTo.js
Created March 30, 2016 16:43 — forked from james2doyle/scrollTo.js
a native scrollTo function in javascript that uses requestAnimationFrame and easing for animation
// easing functions http://goo.gl/5HLl8
Math.easeInOutQuad = function (t, b, c, d) {
t /= d/2;
if (t < 1) {
return c/2*t*t + b
}
t--;
return -c/2 * (t*(t-2) - 1) + b;
};
@exonen
exonen / Orientation
Created September 5, 2013 19:57
Orientation
// Detect whether device supports orientationchange event, otherwise fall back to
// the resize event.
var supportsOrientationChange = 'onorientationchange' in window,
orientationEvent = supportsOrientationChange ? 'orientationchange' : 'resize';
window.addEventListener(orientationEvent, function() {
window.alert('HOLY ROTATING SCREENS BATMAN:' + window.orientation + ' ' + screen.width);
}, false);
document.getElementsByClassName && (function(){
var gists = document.getElementsByClassName('gist');
function embed(id, file, i, tag) {
window['embed_gist_'+i] = function(gist) {
var tmp = document.createElement('div');
tmp.innerHTML = gist.div;
tag.parentNode.replaceChild(tmp.firstChild, tag);
};
var url = 'https://gist.github.com/'+id+'.json?callback=embed_gist_'+i;
if(file) {
@exonen
exonen / randomly reorder child elements using jQuery
Created January 23, 2012 21:36
jQuery plugin to randomly reorder child elements with callback
/**
* Randomly reorder child elements.
* The optional *callback* is called with each child and its new (deep) clone, allowing you to
* copy data over or anything else you may require.
*
* Example usage:
* controls.songs.reorder(function(child, clone) {
* clone.data('info', child.data('info'));
* var id = child.data('info').id;
* if (self.current != undefined && self.current.data('info').id == id) self.current = clone;
@exonen
exonen / ajaxify-html5.js
Created January 12, 2012 00:44 — forked from balupton/README.md
Ajaxify a Website with the HTML5 History API using History.js, jQuery and ScrollTo
// https://gist.github.com/854622
(function(window,undefined){
// Prepare our Variables
var
History = window.History,
$ = window.jQuery,
document = window.document;
// Check to see if History.js is enabled for our Browser