Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SASS Mixin to generate multiple background images
- ```scss
- @mixin multiBg($page: index, $name: bg, $from: 1, $to: 5, $type: jpg) {
- $url_list: ();
- @for $i from $from through $to {
- // I broke constructing the url and adding it to the set into two steps here.
- // We could do this all at once, but separating it can make it easier to read.
- // First, generate the url.
- $url_string: url(/#{$page}/#{$i}_#{name}.#{$type});
- // Then add it to the list (the 'comma' part is important)
- $url_list: append($url_list, $url_string, comma);
- }
- // Done looping? Output the final list!
- background-image: $url_list;
- }
- ```
- Usage:
- ```scss
- .my-multiple-images {
- @include multiBg(cake_covers, circle, 0, 5, png);
- }
- ```
- Result:
- ```css
- .my-multiple-images {
- background-image: url(/cake_covers/0_circle.png), url(/cake_covers/1_circle.png), url(/cake_covers/2_circle.png), url(/cake_covers/3_circle.png), url(/cake_covers/4_circle.png), url(/cake_covers/5_circle.png);
- }
- ```
Add Comment
Please, Sign In to add comment