Guest User

Untitled

a guest
Dec 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. # SASS Mixin to generate multiple background images
  2.  
  3. ```scss
  4. @mixin multiBg($page: index, $name: bg, $from: 1, $to: 5, $type: jpg) {
  5.  
  6. $url_list: ();
  7.  
  8. @for $i from $from through $to {
  9.  
  10. // I broke constructing the url and adding it to the set into two steps here.
  11. // We could do this all at once, but separating it can make it easier to read.
  12.  
  13. // First, generate the url.
  14. $url_string: url(/#{$page}/#{$i}_#{name}.#{$type});
  15.  
  16. // Then add it to the list (the 'comma' part is important)
  17. $url_list: append($url_list, $url_string, comma);
  18.  
  19. }
  20.  
  21. // Done looping? Output the final list!
  22. background-image: $url_list;
  23. }
  24. ```
  25.  
  26. Usage:
  27. ```scss
  28. .my-multiple-images {
  29. @include multiBg(cake_covers, circle, 0, 5, png);
  30. }
  31. ```
  32.  
  33. Result:
  34. ```css
  35. .my-multiple-images {
  36. 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);
  37. }
  38. ```
Add Comment
Please, Sign In to add comment