Skip to content

Instantly share code, notes, and snippets.

View dustintheweb's full-sized avatar
🎯
Focusing

Dustin Hoffmann dustintheweb

🎯
Focusing
View GitHub Profile
@dustintheweb
dustintheweb / convert-string-to-var.js
Created April 26, 2013 16:49
Pass a string into a function and concatenate it into a parseable var
// >> pass a string to the middle of a declared var >>>>>>>>>>>>>>>>
var n1x1, n1x2, n1y1, n1y2;
function someFunc(navNum){
ctx.moveTo(eval(navNum+'x1'), eval(navNum+'y1'));
ctx.lineTo(eval(navNum+'x2'), eval(navNum+'y2'));
// ...
}
@dustintheweb
dustintheweb / self-invoke-function.js
Last active December 16, 2015 15:09
Self invoke a standard function in jQuery
// >> jQuery - Self invoke a standard function >>>>>>>>>>>>>>>>
(function (){
alert('hello world');
})();
@dustintheweb
dustintheweb / lazyloader-skrollr.js
Last active December 16, 2015 14:19
A skrollr.js based lazyloader
// >> Skrollr.js LazyLoader >>>>>>>>>>>>>>>>
// prereq: throttle: https://github.com/cowboy/jquery-throttle-debounce
// note: throttle: when you want to receive constant data from the user
// debounce: when you want to wait for the user to be done
$(function(){
var sec1 = $('#section-1'),
sec2 = $('#section-2'),
@dustintheweb
dustintheweb / horizontal-skroll-shim.js
Last active September 15, 2020 14:59
Simulate a horizontal touch scroll event in skrollr.js
// >> Horizontal Touch Scroll Simulator >>>>>>>>>>>>>>>
// prereq: skrollr.js: https://github.com/Prinzhorn/skrollr
function fakeHorzScroll(){
var tStartX, tStopY, touch, mXPos, xPro;
$(window).bind('touchstart', function(e) {
tStartX = e.originalEvent.touches[0].pageX;
e.preventDefault();
@dustintheweb
dustintheweb / pretty-resize.js
Last active December 16, 2015 13:59
Nicely animate your responsive breaking points
// >> Pretty Resize >>>>>>>>>>>>>>>>
// prereq: debounce: https://github.com/cowboy/jquery-throttle-debounce
function prettyResize(){
var a = '.element-1', // elements resizing
b = '.element-2',
c = '.element-3',
d = '.element-4',
rollout = $('' + a + ',' + b + ',' + c + ',' + d + '');
@dustintheweb
dustintheweb / dynamic-center.js
Last active December 16, 2015 13:59
jQuery - Dynamically center elements
// >> jQuery - Dynamically center elements >>>>>>>>>>>>>>>>
var el_1 = $('.element-1'),
el_2 = $('.element-2'),
el_3 = $('.element-3'),
el_4 = $('.element-4');
// -- X&Y ---------------
function XYmid(){
el_1.css({'marginLeft' : el_1.outerWidth()/-2, 'marginTop' : el_1.outerHeight()/-2});