Skip to content

Instantly share code, notes, and snippets.

View schjetne's full-sized avatar

Jan Schjetne schjetne

  • Oslo Origo
  • Oslo, Norway
View GitHub Profile
@schjetne
schjetne / spacer.scss
Created June 12, 2014 11:33
@mixin spacer(10px 2em 100vh, margin, 4);
@mixin spacer($val, $type:'padding', $scale: 2) {
// Usage:
// @include spacer(10px 2em 100vh, margin, 4);
// or
// @include spacer(10px 2em 100vh);
@if $val != 0 and $val != false {
$keys: top left bottom right;
$vals: 0 0 0 0;
@if length($val) == 1 {
$vals: $val $val $val $val;
@schjetne
schjetne / back-with-fallback.js
Created April 24, 2013 12:12
Code to navigate to previous page in history if it exists, otherwise go back to a default "back" location.
// Use: ><a href="list.html" class="js-back">Go back</a>
$('.js-back').on('click', function(evt) {
if (document.referrer != "") {
evt.preventDefault();
history.back();
}
});
@schjetne
schjetne / img-baseline-flow.js
Created August 20, 2012 15:30
Prevent images from disrupting vertical flow
// Prevent images from disrupting vertical flow
$(window).resize(function() {
var fontSize = parseInt($('body').css('font-size'),0);;
var lineHeight = parseInt($('body').css('line-height'),0);;
$('.baseline').each(function() {
var heightDif = $(this).outerHeight();
$(this).css('margin-bottom', fontSize + heightDif % lineHeight);
});
});
$('.baseline').load(function() { $(window).resize(); });