Skip to content

Instantly share code, notes, and snippets.

@pieterboscapitalid
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pieterboscapitalid/c94635d05b158b7f5e0d to your computer and use it in GitHub Desktop.
Save pieterboscapitalid/c94635d05b158b7f5e0d to your computer and use it in GitHub Desktop.
Preloading svg's the Sass way
// ----
// libsass (v3.2.5)
// ----
$preloaded-images: null;
$svg-path:'test/';
@function preload-image($image-url) {
$preloaded-images : $preloaded-images url($image-url) !global;
@return $preloaded-images;
}
@mixin background-image-svg($img-name) {
background-image: url($svg-path + $img-name + ".svg");
// This function will add the image to the list of images to preload.
$tmp: preload-image($svg-path + $img-name + ".svg");
}
.cool-class {
@include background-image-svg('a');
@include background-image-svg('b');
}
.cooler {
@include background-image-svg('d');
@include background-image-svg('f');
}
body:before {
display: none;
content: $preloaded-images;
}
.cool-class {
background-image: url("test/a.svg");
background-image: url("test/b.svg");
}
.cooler {
background-image: url("test/d.svg");
background-image: url("test/f.svg");
}
body:before {
display: none;
content: url("test/a.svg") url("test/b.svg") url("test/d.svg") url("test/f.svg");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment