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 / 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});
@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 / 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 / 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 / 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 / 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 / scroll-check.js
Last active December 16, 2015 17:50
Check if a user is scrolling
// jquery >> Scroll Check >>>>>>>>>>>>>>>>
// prereq: debounce: https://github.com/cowboy/jquery-throttle-debounce
$(window).scroll($.debounce( 250, true, function(){ // +++ if scrolling
// do something
}));
$(window).scroll($.debounce( 250, function(){ // +++ if not...
// do something else
}));
@dustintheweb
dustintheweb / element-position-fallback.css
Created May 1, 2013 21:39
A third fallback for positioning page elements
-webkit-transform: translate(-50%,-50%);
/* position:relative; top:0; Left:0;
margin: 0 0 0 0; */
@dustintheweb
dustintheweb / responsive-colorbox.js
Last active December 17, 2015 02:19
Make Colorbox modals responsive
// jquery >> Responsive Colorbox >>>>>>>>>>>>>>>>
(function($){
// -- ColorBox Init --------------------------------------------------------------------------------------------------
var resizeTimer, ct, winWidth = $(window).width();
//
$(window).resize(function(){
if (resizeTimer) ct = clearTimeout(resizeTimer);
resizeTimer = window.setTimeout(function() {
if ($('#cboxOverlay').is(':visible')) {
@dustintheweb
dustintheweb / gitignore-not-ignoring.fix
Created May 31, 2013 19:45
The fix for when a file is added to .gitignore, but git is still acknowledging its existence...
1) edit the file as needed and back it up somewhere
2) physically delete the file in question (not the backup)
3) edit .gitignore and add path/filename.file
4) remove the file from git using git rm filename.file
5) git add / commit the change
6) copy / paste the backup back into the source folder
7) git status - if done correctly, git will no longer pick up the file
// this issue typically happens when you add a file to .gitignore after the file has already been checked in