Skip to content

Instantly share code, notes, and snippets.

View joecritch's full-sized avatar

Joe Critchley joecritch

View GitHub Profile
@joecritch
joecritch / gist:929295
Created April 19, 2011 19:07
Part 4 - Wrapper
// '$.fn' is jQuery's prototype. Practically all plugins work this way. It's just that we're not really doing much directly inside of it.
$.fn.simpleScroll = function(conf) {
// If the plugin was to be matched by several elements, this part of the plugin would only run once. But see how we then loop through "this"...?
// (This merges the default options that we namespaced at the beginning, with any new options being passed in by the user)
var conf = $.extend({}, $.motionlab.simpleScroll.conf, conf);
// Okay, now we loop through ALL the matched elements.
return this.each(function() {
@joecritch
joecritch / gist:929275
Created April 19, 2011 18:58
Part 3 - Blueprint
// Give your class a capitalised camel-cased name. You also need to pass 2 things into it: the actual object that the plugin called, and any options that the user has chosen.
function SimpleScroll(root, conf) {
// At this point, "this" is scoped to the SimpleScroll class - let's capture it before it disappears!
var self = this,
// I chose an 'alias' for the main object at this point to make it more in context. This is optional.
cara = root,
// Add any variables you need to calculate and/or track at this point.
item_width = cara.find('li').eq(0).outerWidth(true);
@joecritch
joecritch / gist:929191
Created April 19, 2011 18:32
Part 2 - Options
// Static constructs
$.motionlab = $.motionlab || {};
$.motionlab.simpleScroll = {
conf: {
auto_slide: 0,
hover_pause: 0,
auto_slide_seconds: 1000
}
}
@joecritch
joecritch / gist:929515
Created April 19, 2011 20:16
Example callback
api.onSlide(function(where) {
alert('You just did some sliding to the ' + where);
});
@joecritch
joecritch / gist:929062
Created April 19, 2011 18:04
Creating a closure
(function($) {
// The plugin will go here
}(jQuery);
@joecritch
joecritch / gist:929328
Created April 19, 2011 19:14
Example call
$('.carousel ul').each(function() {
var ul = $(this);
ul.simpleScroll({
auto_slide: 1,
hover_pause: 1
});
});
@joecritch
joecritch / ocanvas-experiment.js
Created March 26, 2011 13:27
Experiments with the new oCanvas library
/* Author: Joe Critchley
oCanvas Experiments
*/
var canvas = oCanvas.create({
canvas: '#canvas',
background: '#222',
fps: 60
});
@joecritch
joecritch / fallback-methods.js
Created March 15, 2011 22:03
Just asking which is the better way..
// Method 1 - how i would do it (although i've only used other lazy loaders before)
if(!Modernizr.inputtypes.date) {
yepnope({
load : [
'scripts/jquery.js',
'scripts/jquery-ui.js',
'css/jquery-ui.css',
'scripts/datepicker.js'
]
@joecritch
joecritch / slantednav.css
Created January 16, 2011 21:12
"A quick example of how to create slanted navigation that uses CSS3 transforms.
#main-nav > ul { overflow: hidden; margin-top: 50px; }
#main-nav > ul > li { float: left; overflow: hidden; padding: 20px; font-size: 18px; margin-left: -35px; }
#main-nav > ul > li:first-child { margin-left: 0px; border-radius: 10px; }
#main-nav > ul > li > a { color: #444; text-decoration: none; overflow: hidden; display: block; -moz-transform: rotate(20deg); -o-transform: rotate(20deg); -webkit-transform: rotate(20deg); background: #bbb; margin-bottom: -100px; margin-top: -70px; height: 150px; border-left: 1px solid white; }
#main-nav > ul > li:first-child > a { border-radius: 10px; border-left: 0; }
#main-nav > ul > li > a > span { overflow: hidden; display: block; -moz-transform: rotate(-20deg); -o-transform: rotate(-20deg); -webkit-transform: rotate(-20deg); padding: 0 20px; margin-top: 57px; }
#main-nav > ul > li > a:hover { background: #aaa; }
#main-nav > ul > li.current > a { background: #000; color: #fff; }
@joecritch
joecritch / taco.css
Created December 27, 2010 23:06
The Taco grid system by @joecritchley
/** -------------------------------------
* Taco. By Joe Critchley (@joecritchley)
*/
.c { width: 978px; margin: 0 auto; }
.c .c { margin: 0 -20px; width: auto; }
.g1, .g2, .g3, .g4, .g5, .g6, .g7, .g8, .g9, .g10, .g11, .g12 { margin-left: 30px; float: left; display: inline; }
.c .c .g1, .c .c .g2, .c .c .g3, .c .c .g4, .c .c .g5, .c .c .g6,
.c .c .g7, .c .c .g8, .c .c .g9, .c .c .g10, .c .c .g11, .c .c .g12 { margin-left: 10px; }
.g1 { width: 54px; } .c .c .g1 { width: 74px; }