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 / simple-parallax.js
Created October 13, 2018 19:13
Simple Parallax
const main = {};
const updateScroll = () => {
main.winScroll = $(window).scrollTop();
};
const parallaxLoad = () => {
const $someEl = $('.someEl');
$someEl.each((i,el) => {
let $el = $(el);
@dustintheweb
dustintheweb / in-viewport.js
Last active October 13, 2018 18:59
Elements in Viewport Fn
const main = {};
const inViewport = ($el) => {
let winTop = main.winScroll;
let winBtm = winTop + main.winHeight;
let $elTop = $el.offset().top;
let $elBtm = $elTop + $el.outerHeight();
return $elBtm > winTop && $elTop < winBtm;
}
if (inViewport($el) === true) {
@dustintheweb
dustintheweb / scroll-direction.js
Created October 13, 2018 18:56
Scroll Direction Fn
const main = {};
const updateScroll = () => {
main.winScroll = $(window).scrollTop();
if (!main.winScrollMem) {
main.winScrollMem = 0;
}
if (main.winScroll > main.winScrollMem) {
main.winScrollDir = 'down';
} else {
main.winScrollDir = 'up';
@dustintheweb
dustintheweb / optimize-typekit-async-load-with-callback
Last active August 29, 2015 14:20
Optimize the Typekit load w/ Async & add a callback
<!-- tk optimize // http://goo.gl/2A1IF7 -->
<script type = "text/javascript" > (function(e) {
var t = 3e3;
if (window.sessionStorage) {
if (sessionStorage.getItem("useTypekit") === "false") {
t = 0;
}
}
var n = {
kitId: "abcd1234",
@dustintheweb
dustintheweb / debug-ajax-console.js
Created April 13, 2015 12:03
Javascript to debug an ajax request
var oXhr;
oXhr = new XMLHttpRequest();
oXhr.id = (new Date()).getTime();
oXhr.onreadystatechange = function() {
if (oXhr.readyState === 4 && (oXhr.status === 200)) {
// code stuffs
console.log(this.id);
}
@dustintheweb
dustintheweb / self-clearing-setinterval-with-callback.js
Created April 11, 2015 03:00
A self clearing setInterval with a callback
var i = 0;
var timer = setInterval(function(){
// stuff
if(i === 5) {
clearInterval(timer);
console.log('callback'); // callback after some time
}
}, 200);
@dustintheweb
dustintheweb / 29392738.md
Created April 2, 2015 16:32
Solution: Correctly configuring a static site with advanced routing - http://stackoverflow.com/posts/29392738

Ok I finally have this figured out.

First off, if you aren't familiar with the way GAE handles templating... it's a bit different than you would expect, but a pillar of getting this to work correctly.

This is what you want at the bottom of your app.yaml

- url: /
  static_files: dist/index.html
  upload: dist/index.html

expiration: "15m"

@dustintheweb
dustintheweb / headroom-smart-offset.js
Created March 19, 2015 19:16
Headroom Smart Offset
// -- headroom ---------------
(function($) {
var headOffset = (app.obj.$section.filter('.feature').height() / 2) - (app.obj.$header.height());
app.obj.$header.headroom({
'offset': headOffset,
'tolerance': 5,
'classes': {
'initial': 'animated',
'pinned': 'slideDown',
'unpinned': 'slideUp'
@dustintheweb
dustintheweb / index.html
Created February 28, 2015 11:43
AngularJS: Multiple ternary statements in ng-class
<!doctype html>
<html ng-app="myApp">
<head>...</head>
<body ng-controller="myController" ng-class="(toggleClass1 ? 'class-1' : '')+' '+(toggleClass2 ? 'class-2' : '')">
<div>
stuff...
<div class="button1" ng-click="$toggleClass1 = !$toggleClass1"></div>
stuff...
<div class="button2" ng-click="$toggleClass2 = !$toggleClass2"></div>
</div>
@dustintheweb
dustintheweb / index.html
Created February 28, 2015 11:14
AngularJS: Toggle an external class from a click event inside of an include
<!doctype html>
<html ng-app="myApp">
<head>...</head>
<body ng-controller="myController" ng-class="toggleClass ? 'click-active' : 'click-inactive'">
<div ng-include="/path/myInclude.html"></div>
</body>
</html>