A Pen by Alexander Johansson on CodePen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Handlebar helper | |
Handlebars.registerHelper('or', function () { | |
var args = arguments; | |
for (var i in args) { | |
if (args[i]) { | |
return args[i]; | |
} | |
} | |
return null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin background-image2x($image, $extension: 'png') { | |
$imageOrig: "#{$image}.#{$extension}"; | |
$image2x: "#{$image}@2x.#{$extension}"; | |
$width: image-width($imageOrig); | |
$height: image-height($imageOrig); | |
background-image: image-url($imageOrig); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@mixin responsive-full-width-image($image) { | |
@include box-sizing(content-box); | |
width: 100%; | |
padding-top: percentage(image-height($image) / image-width($image)); | |
background-image: image-url($image); | |
background-repeat: no-repeat; | |
background-size: contain; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// declare in your variables-file | |
$relative-image-path = '../images/'; | |
$retina = '(-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi)'; | |
responsive-image($image) { | |
$path = $relative-image-path + $image; | |
$ext = extname($path); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="images/header.png" data-srcorig="images/[email protected]"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Uses CSS hack in order to make an element maintain the aspect ratio of supplied background-image | |
// Latest version available @ https://gist.github.com/KATT/8283246 | |
// Demo @ http://codepen.io/KATT/pen/yBrni | |
responsive-image($image, $width = false, $height = false) { | |
$external = match('^https?:\/\/', $image); | |
error('expect width and height on external images') if $external and !($width or $height) | |
unless $width and $height { | |
$size = image-size($image); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
background-x2image($image) { | |
$ext = extname($image); | |
$image2x = pathjoin(dirname($image), basename($image, $ext) + '@2x' + $ext); | |
background-image: url($public-image-path + $image); | |
@media $retina { | |
background-image: url($public-image-path + $image2x); | |
} | |
} |