Skip to content

Instantly share code, notes, and snippets.

@travhimself
travhimself / getCookieVal.js
Created March 9, 2018 23:18
get value of cookie entry by name
function getCookieVal(name) {
let cookies = document.cookie.split('; ');
for (let i = 0; i < cookies.length; i++) {
let parts = cookies[i].split(/=(.+)/);
if (parts[0] === name) {
return parts[1];
}
}
}
// search for a DOM element every rendering frame until it exists
//
// borrowed from:
// https://swizec.com/blog/how-to-properly-wait-for-dom-elements-to-show-up-in-modern-browsers/swizec/6663
function lookforelement() {
if ( !$('.element').size() ) {
window.requestAnimationFrame(lookforelement);
} else {
console.log('found element');
// determine "active" section as user scrolls
var $sections = $('body section');
$window.scroll( function(e) {
$.each($sections, function(i, el) {
// measure the distance from the bottom of the element to the top of the viewport
var offsetpadding = 100; // optional padding from top of viewport
var sectionoffset = $(el).offset().top + $(el).outerHeight() - offsetpadding - $window.scrollTop();
@travhimself
travhimself / gist:133fe954ab73236f4fe3
Created June 12, 2015 03:50
Explanation of :nth-child
div:nth-child(xn+y) {
/*
this evaluates like "x*n+y"
x is cycle size
n represents a counter, starting at 0
y is an offset
*/
}
div:nth-child(3) {
@travhimself
travhimself / gist:223be503c7ee3539c4fc
Created July 8, 2014 22:13
granular css shadows with multiple rules
/*
use x-shadow and y-shadow to apply style on a specific side
blur == width of x or y value
spread == negative of x or y value
the below rule would apply style to all four sides of an element (in order: top, right, bottom, left)
combine as desired to apply only to certain sides
works best for inset shadows
@travhimself
travhimself / gist:6573171
Last active December 23, 2015 03:28
Meta tags to disable caching (useful for testing mobile Safari)
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="-1">
@travhimself
travhimself / gist:6546838
Last active December 22, 2015 23:29
js function to grab get paramaters from the URL
var getparams = function(param) {
var url = window.location.search.substring(1);
var urlvars = url.split('&');
for (var i = 0; i < urlvars.length; i++) {
var paramname = urlvars[i].split('=');
if ( paramname[0] == param) {
return paramname[1];
}
}
};
@travhimself
travhimself / gist:6337801
Created August 26, 2013 03:05
Fix the antialiasing on light text sitting on dark background
-webkit-font-smoothing: antialiased;
div {
position: relative;
z-index: 1;
}
div:after {
content: '';
position: absolute;
z-index: -1;
top: 0;
@travhimself
travhimself / gist:2815834
Created May 27, 2012 20:36
js jquery blocks
$(document).ready(function() {
// fire when the DOM is ready
});
$(window).load(function() {
// fire after page has been rendered
});
$(window).unload(function() {
// fire when user leaves the page