Skip to content

Instantly share code, notes, and snippets.

View mediaupstream's full-sized avatar
🍉

Derek Anderson mediaupstream

🍉
View GitHub Profile
@mediaupstream
mediaupstream / gist:1003983
Created June 2, 2011 05:31
usage examples for the jQuery plugin: galleryFocus
/* ## BASIC USAGE ## */
$('#gallery img').galleryFocus();
/* ## OPTIONS ## */
$('#gallery img').galleryFocus({
// 'radius' - default: 400 - set the source radius size
'radius': 800,
@mediaupstream
mediaupstream / gist:1112173
Created July 28, 2011 18:26
jQuery.eachStep - Demo One
<script type="text/javascript">
// Toggle the .rotate class on all demo kitties in order
// with a delay of 200ms each step
$('#demo1 img').eachStep(200, function(i, el, duration){
$(el).toggleClass('rotate');
});
</script>
<div id="demo1">
<img src="http://placekitten.com/101/80">
@mediaupstream
mediaupstream / gist:1112359
Last active September 26, 2015 14:38
jQuery eachStep - The Problem
$('img').each(function(i, el){
// Add the class .rotate to all images at once
$(this).addClass('rotate');
});
@mediaupstream
mediaupstream / gist:1113256
Created July 29, 2011 06:12
jQuery.eachStep - The Solution
// Add the class '.rotate' to every image in order
$('img').each(function(i, el) {
window.setTimeout(function(){
$(el).addClass('animate');
}, 400 * i);
});
@mediaupstream
mediaupstream / jquery.eachStep.demo2.html
Created July 29, 2011 06:42
jQuery.eachStep - Demo Two
<script type="text/javascript">
var collection = [
'#777777', '#444444', '#222222', '#249adb',
'#fc41a9', '#ffe200', '#faa653', '#007791'
];
$.eachStep(collection, '600', function(key, val, duration){
// each step of the collection animate the .demo2-box backgroundColor
// (requires the jquery.color plugin)
$('.demo2-box').animate({'backgroundColor': val}, duration);
/**
* Get the names of the arguments of any function
*/
var getFnArgs = function(fn){
var args = fn.toString().lines()[0];
return args.replace('function (', '').replace('){', '').split(', ');
};
// usage
@mediaupstream
mediaupstream / random.js
Created September 20, 2011 19:35
Random numbers, 3 ways - a Javascript Snippet.
/**
* Random numbers, 3 ways. Usage:
* - random() : returns a random integer
* - random(30) : returns a random integer from 0 to 30
* - random(20, 50) : returns a random integer from 20 to 50
*/
var random = function() {
var f = Math.floor, r = Math.random, a = arguments;
switch(a.length){
case 0: return f(r()); break;
@mediaupstream
mediaupstream / mkb_names_array.js
Created September 29, 2011 06:09
Mortal Kombat Character Names as a Javascript Array
// Mortal Kombat Character Names
// - encoded in js array format from the list on wikipedia:
// - http://en.wikipedia.org/wiki/List_of_Mortal_Kombat_characters
var names = [
'Goro',
'Johnny Cage',
'Kano',
'Liu Kang',
'Raiden',
'Reptile',
@mediaupstream
mediaupstream / example.js
Created October 3, 2011 21:29
Load Images from JSON into AnythingSlider
/**
* file: images.json
*/
{
"images": [
{"title": "Image One", "url": "image1.jpg", "rating": "3.5"},
{"title": "Image Two", "url": "image2.jpg", "rating": "1"},
{"title": "Image Three", "url": "image3.jpg", "rating": "5"}
]
}
@mediaupstream
mediaupstream / json2xml.js
Created December 19, 2011 06:57
json2xml - Convert an xml2js JSON object back to XML
/**
* json2xml - Convert an xml2js JSON object back to XML
*
* @author Derek Anderson
* @copyright 2011 Media Upstream
* @license MIT License
*
* Usage:
*
* json2xml({"Foo": "@": { "baz": "bar", "production":"true" }}, "Test", function(xml){